Skip to content

Commit

Permalink
Allow Netty AppServer to respond to HEAD requests
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Nov 24, 2020
1 parent f9e8ce2 commit 679670b
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.concurrent.Executors;
import java.util.logging.Logger;

import static io.netty.handler.codec.http.HttpMethod.HEAD;
import static org.openqa.selenium.remote.http.Contents.memoize;

class RequestConverter extends SimpleChannelInboundHandler<HttpObject> {
Expand Down Expand Up @@ -126,11 +127,15 @@ private HttpRequest createRequest(

// Attempt to map the netty method
HttpMethod method;
try {
method = HttpMethod.valueOf(nettyRequest.method().name());
} catch (IllegalArgumentException e) {
ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.METHOD_NOT_ALLOWED));
return null;
if (nettyRequest.method().equals(HEAD)) {
method = HttpMethod.GET;
} else {
try {
method = HttpMethod.valueOf(nettyRequest.method().name());
} catch (IllegalArgumentException e) {
ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.METHOD_NOT_ALLOWED));
return null;
}
}

QueryStringDecoder decoder = new QueryStringDecoder(nettyRequest.uri());
Expand Down

0 comments on commit 679670b

Please sign in to comment.