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

The following examples show how to use io.netty.handler.codec.http.HttpMethod#OPTIONS . 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: Http2ServerUpgradeCodecTest.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
private static void testUpgrade(Http2ConnectionHandler handler) {
    FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "*");
    request.headers().set(HttpHeaderNames.HOST, "netty.io");
    request.headers().set(HttpHeaderNames.CONNECTION, "Upgrade, HTTP2-Settings");
    request.headers().set(HttpHeaderNames.UPGRADE, "h2c");
    request.headers().set("HTTP2-Settings", "AAMAAABkAAQAAP__");

    EmbeddedChannel channel = new EmbeddedChannel(new ChannelInboundHandlerAdapter());
    ChannelHandlerContext ctx = channel.pipeline().firstContext();
    Http2ServerUpgradeCodec codec = new Http2ServerUpgradeCodec("connectionHandler", handler);
    assertTrue(codec.prepareUpgradeResponse(ctx, request, new DefaultHttpHeaders()));
    codec.upgradeTo(ctx, request);
    // Flush the channel to ensure we write out all buffered data
    channel.flush();

    assertSame(handler, channel.pipeline().remove("connectionHandler"));
    assertNull(channel.pipeline().get(handler.getClass()));
    assertTrue(channel.finish());

    // Check that the preface was send (a.k.a the settings frame)
    ByteBuf settingsBuffer = channel.readOutbound();
    assertNotNull(settingsBuffer);
    settingsBuffer.release();

    assertNull(channel.readOutbound());
}
 
Example 2
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 3
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 4
Source File: Http2ClientUpgradeCodecTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private static void testUpgrade(Http2ConnectionHandler handler) throws Exception {
    FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "*");

    EmbeddedChannel channel = new EmbeddedChannel(new ChannelInboundHandlerAdapter());
    ChannelHandlerContext ctx = channel.pipeline().firstContext();
    Http2ClientUpgradeCodec codec = new Http2ClientUpgradeCodec("connectionHandler", handler);
    codec.setUpgradeHeaders(ctx, request);
    // Flush the channel to ensure we write out all buffered data
    channel.flush();

    codec.upgradeTo(ctx, null);
    assertNotNull(channel.pipeline().get("connectionHandler"));

    assertTrue(channel.finishAndReleaseAll());
}
 
Example 5
Source File: ModelServerTest.java    From multi-model-server with Apache License 2.0 5 votes vote down vote up
private void testRoot(Channel channel, String expected) throws InterruptedException {
    result = null;
    latch = new CountDownLatch(1);
    HttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "/");
    channel.writeAndFlush(req).sync();
    latch.await();

    Assert.assertEquals(result, expected);
}
 
Example 6
Source File: ModelServerTest.java    From multi-model-server with Apache License 2.0 5 votes vote down vote up
private void testDescribeApi(Channel channel) throws InterruptedException {
    result = null;
    latch = new CountDownLatch(1);
    HttpRequest req =
            new DefaultFullHttpRequest(
                    HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "/predictions/noop_v0.1");
    channel.writeAndFlush(req);
    latch.await();

    Assert.assertEquals(result, noopApiResult);
}
 
Example 7
Source File: ModelServerTest.java    From multi-model-server with Apache License 2.0 5 votes vote down vote up
private void testInvalidDescribeModel() throws InterruptedException {
    Channel channel = connect(false);
    Assert.assertNotNull(channel);

    HttpRequest req =
            new DefaultFullHttpRequest(
                    HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "/predictions/InvalidModel");
    channel.writeAndFlush(req).sync();
    channel.closeFuture().sync();

    ErrorResponse resp = JsonUtils.GSON.fromJson(result, ErrorResponse.class);

    Assert.assertEquals(resp.getCode(), HttpResponseStatus.NOT_FOUND.code());
    Assert.assertEquals(resp.getMessage(), "Model not found: InvalidModel");
}
 
Example 8
Source File: TestUtils.java    From serve with Apache License 2.0 4 votes vote down vote up
public static void getRoot(Channel channel) throws InterruptedException {
    HttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "/");
    channel.writeAndFlush(req).sync();
}
 
Example 9
Source File: TestUtils.java    From serve with Apache License 2.0 4 votes vote down vote up
public static void describeModelApi(Channel channel, String modelName) {
    HttpRequest req =
            new DefaultFullHttpRequest(
                    HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "/predictions/" + modelName);
    channel.writeAndFlush(req);
}
 
Example 10
Source File: Http2CorsHandler.java    From xrpc with Apache License 2.0 4 votes vote down vote up
private HttpMethod requestMethod(Http2Headers headers, boolean isPreflight) {
  return isPreflight
      ? HttpMethod.valueOf(headers.get(HttpHeaderNames.ACCESS_CONTROL_REQUEST_METHOD).toString())
      : HttpMethod.OPTIONS;
}
 
Example 11
Source File: XmlRpcServerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isSupported(@Nonnull FullHttpRequest request) {
  return request.method() == HttpMethod.POST || request.method() == HttpMethod.OPTIONS;
}