List of usage examples for io.netty.handler.codec.http HttpResponseStatus CONTINUE
HttpResponseStatus CONTINUE
To view the source code for io.netty.handler.codec.http HttpResponseStatus CONTINUE.
Click Source Link
From source file:org.elasticsearch.http.nio.NioHttpServerTransportTests.java
License:Apache License
/** * Test that {@link NioHttpServerTransport} supports the "Expect: 100-continue" HTTP header * @throws InterruptedException if the client communication with the server is interrupted *//*from ww w . j ava2 s . c o m*/ public void testExpectContinueHeader() throws InterruptedException { final Settings settings = Settings.EMPTY; final int contentLength = randomIntBetween(1, HttpTransportSettings.SETTING_HTTP_MAX_CONTENT_LENGTH.get(settings).bytesAsInt()); runExpectHeaderTest(settings, HttpHeaderValues.CONTINUE.toString(), contentLength, HttpResponseStatus.CONTINUE); }
From source file:org.elasticsearch.http.nio.NioHttpServerTransportTests.java
License:Apache License
private void runExpectHeaderTest(final Settings settings, final String expectation, final int contentLength, final HttpResponseStatus expectedStatus) throws InterruptedException { final HttpServerTransport.Dispatcher dispatcher = new HttpServerTransport.Dispatcher() { @Override/*from w w w.ja va2 s .c o m*/ public void dispatchRequest(RestRequest request, RestChannel channel, ThreadContext threadContext) { channel.sendResponse( new BytesRestResponse(OK, BytesRestResponse.TEXT_CONTENT_TYPE, new BytesArray("done"))); } @Override public void dispatchBadRequest(RestRequest request, RestChannel channel, ThreadContext threadContext, Throwable cause) { throw new AssertionError(); } }; try (NioHttpServerTransport transport = new NioHttpServerTransport(settings, networkService, bigArrays, pageRecycler, threadPool, xContentRegistry(), dispatcher)) { transport.start(); final TransportAddress remoteAddress = randomFrom(transport.boundAddress().boundAddresses()); try (NioHttpClient client = new NioHttpClient()) { final FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/"); request.headers().set(HttpHeaderNames.EXPECT, expectation); HttpUtil.setContentLength(request, contentLength); final FullHttpResponse response = client.post(remoteAddress.address(), request); try { assertThat(response.status(), equalTo(expectedStatus)); if (expectedStatus.equals(HttpResponseStatus.CONTINUE)) { final FullHttpRequest continuationRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", Unpooled.EMPTY_BUFFER); final FullHttpResponse continuationResponse = client.post(remoteAddress.address(), continuationRequest); try { assertThat(continuationResponse.status(), is(HttpResponseStatus.OK)); assertThat(new String(ByteBufUtil.getBytes(continuationResponse.content()), StandardCharsets.UTF_8), is("done")); } finally { continuationResponse.release(); } } } finally { response.release(); } } } }
From source file:org.glassfish.jersey.netty.httpserver.JerseyServerHandler.java
License:Open Source License
@Override public void channelRead(final ChannelHandlerContext ctx, Object msg) { if (msg instanceof HttpRequest) { final HttpRequest req = (HttpRequest) msg; if (HttpUtil.is100ContinueExpected(req)) { ctx.write(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE)); }//from www.j av a2 s.c om isList.clear(); // clearing the content - possible leftover from previous request processing. final ContainerRequest requestContext = createContainerRequest(ctx, req); requestContext.setWriter(new NettyResponseWriter(ctx, req, container)); // must be like this, since there is a blocking read from Jersey container.getExecutorService().execute(new Runnable() { @Override public void run() { container.getApplicationHandler().handle(requestContext); } }); } if (msg instanceof HttpContent) { HttpContent httpContent = (HttpContent) msg; ByteBuf content = httpContent.content(); if (content.isReadable()) { isList.add(new ByteBufInputStream(content)); } if (msg instanceof LastHttpContent) { isList.add(NettyInputStream.END_OF_INPUT); } } }
From source file:org.jooby.internal.netty.NettyHandler.java
License:Apache License
@Override public void channelRead0(final ChannelHandlerContext ctx, final Object msg) { if (msg instanceof HttpRequest) { ctx.channel().attr(NettyRequest.NEED_FLUSH).set(true); HttpRequest req = (HttpRequest) msg; ctx.channel().attr(PATH).set(req.method().name() + " " + req.uri()); if (HttpUtil.is100ContinueExpected(req)) { ctx.write(new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.CONTINUE)); }// w w w.j ava 2s . co m boolean keepAlive = HttpUtil.isKeepAlive(req); try { String streamId = req.headers().get(STREAM_ID); handler.handle(new NettyRequest(ctx, req, tmpdir, wsMaxMessageSize), new NettyResponse(ctx, bufferSize, keepAlive, streamId)); } catch (Throwable ex) { exceptionCaught(ctx, ex); } } else if (msg instanceof WebSocketFrame) { Attribute<NettyWebSocket> ws = ctx.channel().attr(NettyWebSocket.KEY); ws.get().handle(msg); } }
From source file:org.restexpress.util.HttpSpecificationTest.java
License:Apache License
@Test public void shouldPassOn100WithoutBody() { response.setResponseStatus(HttpResponseStatus.CONTINUE); response.setBody(null); HttpSpecification.enforce(response); }
From source file:org.restexpress.util.HttpSpecificationTest.java
License:Apache License
@Test(expected = HttpSpecificationException.class) public void shouldThrowExceptionOn100WithBody() { response.setResponseStatus(HttpResponseStatus.CONTINUE); response.setBody("Should not be allowed."); HttpSpecification.enforce(response); }
From source file:org.restexpress.util.HttpSpecificationTest.java
License:Apache License
@Test(expected = HttpSpecificationException.class) public void shouldThrowExceptionOn100WithContentType() { response.setResponseStatus(HttpResponseStatus.CONTINUE); response.addHeader(HttpHeaders.Names.CONTENT_TYPE, ContentType.XML); HttpSpecification.enforce(response); }
From source file:org.restexpress.util.HttpSpecificationTest.java
License:Apache License
@Test(expected = HttpSpecificationException.class) public void shouldThrowExceptionOn100WithContentLength() { response.setResponseStatus(HttpResponseStatus.CONTINUE); response.addHeader(HttpHeaders.Names.CONTENT_LENGTH, "25"); HttpSpecification.enforce(response); }
From source file:org.restexpress.util.HttpSpecificationTest.java
License:Apache License
@Test public void shouldNotAllowContentType() { response.setResponseStatus(HttpResponseStatus.CONTINUE); assertFalse(HttpSpecification.isContentTypeAllowed(response)); response.setResponseStatus(HttpResponseStatus.NO_CONTENT); assertFalse(HttpSpecification.isContentTypeAllowed(response)); response.setResponseStatus(HttpResponseStatus.NOT_MODIFIED); assertFalse(HttpSpecification.isContentTypeAllowed(response)); }
From source file:org.restexpress.util.HttpSpecificationTest.java
License:Apache License
@Test public void shouldNotAllowContentLength() { response.setResponseStatus(HttpResponseStatus.CONTINUE); assertFalse(HttpSpecification.isContentLengthAllowed(response)); response.setResponseStatus(HttpResponseStatus.NO_CONTENT); assertFalse(HttpSpecification.isContentLengthAllowed(response)); response.setResponseStatus(HttpResponseStatus.NOT_MODIFIED); assertFalse(HttpSpecification.isContentLengthAllowed(response)); }