Java Code Examples for io.netty.handler.codec.http.HttpMethod#HEAD

The following examples show how to use io.netty.handler.codec.http.HttpMethod#HEAD . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReactorNettySender.java    From micrometer with Apache License 2.0 6 votes vote down vote up
private HttpMethod toNettyHttpMethod(Method method) {
    switch (method) {
        case PUT:
            return HttpMethod.PUT;
        case POST:
            return HttpMethod.POST;
        case HEAD:
            return HttpMethod.HEAD;
        case GET:
            return HttpMethod.GET;
        case DELETE:
            return HttpMethod.DELETE;
        case OPTIONS:
            return HttpMethod.OPTIONS;
        default:
            throw new UnsupportedOperationException("http method " + method.toString() + " is not supported by the reactor netty client");
    }
}
 
Example 2
Source File: ThriftUnmarshaller.java    From xio with Apache License 2.0 6 votes vote down vote up
private static HttpMethod build(Http1Method method) {
  if (method != null) {
    switch (method) {
      case CONNECT:
        return HttpMethod.CONNECT;
      case DELETE:
        return HttpMethod.DELETE;
      case GET:
        return HttpMethod.GET;
      case HEAD:
        return HttpMethod.HEAD;
      case OPTIONS:
        return HttpMethod.OPTIONS;
      case PATCH:
        return HttpMethod.PATCH;
      case POST:
        return HttpMethod.POST;
      case PUT:
        return HttpMethod.PUT;
      case TRACE:
        return HttpMethod.TRACE;
    }
  }
  return null;
}
 
Example 3
Source File: NettyResponseChannelTest.java    From ambry with Apache License 2.0 6 votes vote down vote up
/**
 * Tests keep-alive for different HTTP methods and error statuses.
 */
@Test
public void keepAliveTest() {
  HttpMethod[] HTTP_METHODS = {HttpMethod.POST, HttpMethod.PUT, HttpMethod.GET, HttpMethod.HEAD, HttpMethod.DELETE};
  EmbeddedChannel channel = createEmbeddedChannel();
  for (HttpMethod httpMethod : HTTP_METHODS) {
    for (RestServiceErrorCode errorCode : RestServiceErrorCode.values()) {
      channel = doKeepAliveTest(channel, httpMethod, errorCode, getExpectedHttpResponseStatus(errorCode), 0, null);
    }
    channel = doKeepAliveTest(channel, httpMethod, null, HttpResponseStatus.INTERNAL_SERVER_ERROR, 0, null);
    channel = doKeepAliveTest(channel, httpMethod, null, HttpResponseStatus.INTERNAL_SERVER_ERROR, 0, true);
    channel = doKeepAliveTest(channel, httpMethod, null, HttpResponseStatus.INTERNAL_SERVER_ERROR, 0, false);
  }
  // special test for put because the keep alive depends on content size (0 already tested above)
  channel = doKeepAliveTest(channel, HttpMethod.PUT, null, HttpResponseStatus.INTERNAL_SERVER_ERROR, 1, null);
  channel = doKeepAliveTest(channel, HttpMethod.PUT, null, HttpResponseStatus.INTERNAL_SERVER_ERROR, 100, null);
  channel.close();
}
 
Example 4
Source File: WebServer.java    From krpc with Apache License 2.0 5 votes vote down vote up
private void receiveStatic(String connId, DefaultWebReq req) {
    if (req.getMethod() == HttpMethod.GET || req.getMethod() == HttpMethod.HEAD) {
        File file = routeService.findStaticFile(req.getHostNoPort(), req.getPath());
        if (file != null) {
            boolean done = routeStaticFile(connId, req, file);
            if (done) return;
        }
    }

    DefaultWebRes res = generateError(req, RetCodes.HTTP_URL_NOT_FOUND, 404, null);
    httpTransport.send(connId, res);
}
 
Example 5
Source File: THttp2Client.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    final DefaultFullHttpRequest upgradeRequest =
            new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.HEAD, "/");
    ctx.writeAndFlush(upgradeRequest);

    ctx.fireChannelActive();

    // Done with this handler, remove it from the pipeline.
    ctx.pipeline().remove(this);

    configureEndOfPipeline(ctx.pipeline());
}
 
Example 6
Source File: HttpRequestHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean isSupported(FullHttpRequest request) {
  return request.method() == HttpMethod.GET || request.method() == HttpMethod.HEAD;
}
 
Example 7
Source File: MethodConstraintTest.java    From karyon with Apache License 2.0 4 votes vote down vote up
@Test
public void testMethodConstraint() throws Exception {
    MethodConstraintKey<ByteBuf> key = new MethodConstraintKey<ByteBuf>(HttpMethod.HEAD);
    boolean keyApplicable = doApply(key, "a/b/c", HttpMethod.HEAD);
    Assert.assertTrue("Http Method style constraint failed.", keyApplicable);
}
 
Example 8
Source File: MethodConstraintTest.java    From karyon with Apache License 2.0 4 votes vote down vote up
@Test
public void testMethodConstraintFail() throws Exception {
    MethodConstraintKey<ByteBuf> key = new MethodConstraintKey<ByteBuf>(HttpMethod.HEAD);
    boolean keyApplicable = doApply(key, "a/b/c", HttpMethod.GET);
    Assert.assertFalse("Http Method style constraint failed.", keyApplicable);
}