Skip to content

Commit

Permalink
Ensure we report the user-agent in netty http requests
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Mar 30, 2020
1 parent a2ffa85 commit cddf89f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpVersion;
import org.openqa.selenium.remote.http.AddSeleniumUserAgent;
import org.openqa.selenium.remote.http.ClientConfig;
import org.openqa.selenium.remote.http.Contents;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.http.HttpHandler;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;
import org.openqa.selenium.remote.http.RemoteCall;
Expand Down Expand Up @@ -79,7 +79,6 @@ class NettyDomainSocketClient extends RemoteCall implements HttpClient {
private final EventLoopGroup eventLoopGroup;
private final Class<? extends Channel> channelClazz;
private final String path;
private final HttpHandler handler;

public NettyDomainSocketClient(ClientConfig config) {
super(config);
Expand All @@ -97,7 +96,6 @@ public NettyDomainSocketClient(ClientConfig config) {
}

this.path = uri.getPath();
this.handler = config.filter().andFinally(this);
}

@Override
Expand Down Expand Up @@ -133,6 +131,9 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
uri.toString(),
Unpooled.wrappedBuffer(bytes));
req.getHeaderNames().forEach(name -> req.getHeaders(name).forEach(value -> fullRequest.headers().add(name, value)));
if (req.getHeader("User-Agent") == null) {
fullRequest.headers().set("User-Agent", AddSeleniumUserAgent.USER_AGENT);
}
fullRequest.headers().set(HttpHeaderNames.HOST, "localhost");
fullRequest.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
fullRequest.headers().set(HttpHeaderNames.CONTENT_LENGTH, bytes.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.asynchttpclient.Request;
import org.asynchttpclient.RequestBuilder;
import org.asynchttpclient.Response;
import org.openqa.selenium.remote.http.AddSeleniumUserAgent;
import org.openqa.selenium.remote.http.Contents;
import org.openqa.selenium.remote.http.HttpMethod;
import org.openqa.selenium.remote.http.HttpRequest;
Expand Down Expand Up @@ -66,6 +67,9 @@ protected static Request toNettyRequest(URI baseUrl, HttpRequest request) {
builder.addHeader(name, value);
}
}
if (request.getHeader("User-Agent") == null) {
builder.addHeader("User-Agent", AddSeleniumUserAgent.USER_AGENT);
}

String info = baseUrl.getUserInfo();
if (!Strings.isNullOrEmpty(info)) {
Expand Down

0 comments on commit cddf89f

Please sign in to comment.