Some robustness fix

This commit is contained in:
Ziver Koc 2024-03-15 00:09:35 +01:00
parent 5fd11daf15
commit 186714d0b2

View file

@ -32,6 +32,7 @@ import javax.net.ssl.SSLSocketFactory;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
import java.util.HashMap;
@ -90,6 +91,14 @@ public class HttpClient implements AutoCloseable {
this.type = type;
}
public void setURL(String url) {
try {
setURL(new HttpURL(url));
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
}
public void setURL(URL url) {
setURL(new HttpURL(url));
}
@ -140,7 +149,9 @@ public class HttpClient implements AutoCloseable {
*/
public HttpHeader send() throws IOException {
int port = 80;
if (url.getPort() > 0)
if (url == null)
throw new IllegalArgumentException("No URL defined for request.");
else if (url.getPort() > 0)
port = url.getPort();
else if ("https".equals(url.getProtocol()))
port = 443;