[main] HttpUtils: allow configuring user agent
This commit is contained in:
parent
87f5751fa1
commit
fd71209d61
|
@ -21,6 +21,7 @@ import java.util.stream.Collectors;
|
|||
import java.util.stream.Stream;
|
||||
|
||||
public class HttpUtils {
|
||||
private static String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36";
|
||||
static {
|
||||
// Enables HTTPS proxying
|
||||
System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
|
||||
|
@ -61,6 +62,11 @@ public class HttpUtils {
|
|||
})
|
||||
.build();
|
||||
|
||||
public void setUserAgent(String hostname) {
|
||||
if (hostname == null || hostname.isEmpty()) throw new IllegalArgumentException("Hostname cannot be empty");
|
||||
HttpUtils.userAgent = hostname;
|
||||
}
|
||||
|
||||
private enum Method {
|
||||
GET,
|
||||
POST
|
||||
|
@ -77,7 +83,7 @@ public class HttpUtils {
|
|||
this.url = url.replace(" ", "%20");
|
||||
this.builder = HttpRequest.newBuilder()
|
||||
.uri(new URI(this.url))
|
||||
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
|
||||
.header("User-Agent", userAgent);
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue