io.netty.handler.codec.http.HttpObjectDecoder Java Examples

The following examples show how to use io.netty.handler.codec.http.HttpObjectDecoder. 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: StreamingAsyncHttpClient.java    From riposte with Apache License 2.0 5 votes vote down vote up
protected static int determineHttpClientCodecInboundState(HttpClientCodec currentCodec) {
    try {
        HttpObjectDecoder decoder = (HttpObjectDecoder) httpClientCodecInboundHandlerField.get(currentCodec);
        return ((Enum) httpObjectDecoderCurrentStateField.get(decoder)).ordinal();
    }
    catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
Example #2
Source File: HttpServerTests.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
@Test
public void httpServerRequestConfigInjectAttributes() {
	AtomicReference<Channel> channelRef = new AtomicReference<>();
	AtomicReference<Boolean> validate = new AtomicReference<>();
	AtomicReference<Integer> chunkSize = new AtomicReference<>();
	HttpServer server =
			HttpServer.create()
			          .httpRequestDecoder(opt -> opt.maxInitialLineLength(123)
			                                        .maxHeaderSize(456)
			                                        .maxChunkSize(789)
			                                        .validateHeaders(false)
			                                        .initialBufferSize(10))
			          .handle((req, resp) -> req.receive().then(resp.sendNotFound()))
			          .doOnConnection(c -> {
			                      channelRef.set(c.channel());
			                      HttpServerCodec codec = c.channel()
			                                               .pipeline()
			                                               .get(HttpServerCodec.class);
			                      HttpObjectDecoder decoder = (HttpObjectDecoder) getValueReflection(codec, "inboundHandler", 1);
			                      chunkSize.set((Integer) getValueReflection(decoder, "maxChunkSize", 2));
			                      validate.set((Boolean) getValueReflection(decoder, "validateHeaders", 2));
			                  })
			          .wiretap(true);

	disposableServer = server.bindNow();

	HttpClient.create()
	          .remoteAddress(disposableServer::address)
	          .post()
	          .uri("/")
	          .send(ByteBufFlux.fromString(Mono.just("bodysample")))
	          .responseContent()
	          .aggregate()
	          .asString()
	          .block();

	assertThat(channelRef.get()).isNotNull();
	assertThat(chunkSize.get()).as("line length").isEqualTo(789);
	assertThat(validate.get()).as("validate headers").isFalse();
}
 
Example #3
Source File: HttpClientTest.java    From reactor-netty with Apache License 2.0 4 votes vote down vote up
@Test
public void httpClientResponseConfigInjectAttributes() {
	AtomicReference<Channel> channelRef = new AtomicReference<>();
	AtomicReference<Boolean> validate = new AtomicReference<>();
	AtomicReference<Integer> chunkSize = new AtomicReference<>();

	disposableServer =
			HttpServer.create()
			          .handle((req, resp) -> req.receive()
			                                    .then(resp.sendNotFound()))
			          .wiretap(true)
			          .bindNow();

	createHttpClientForContextWithAddress()
	        .httpResponseDecoder(opt -> opt.maxInitialLineLength(123)
	                                       .maxHeaderSize(456)
	                                       .maxChunkSize(789)
	                                       .validateHeaders(false)
	                                       .initialBufferSize(10)
	                                       .failOnMissingResponse(true)
	                                       .parseHttpAfterConnectRequest(true))
	        .doOnConnected(c -> {
	                    channelRef.set(c.channel());
	                    HttpClientCodec codec = c.channel()
	                                             .pipeline()
	                                             .get(HttpClientCodec.class);
	                    HttpObjectDecoder decoder = (HttpObjectDecoder) getValueReflection(codec, "inboundHandler", 1);
	                    chunkSize.set((Integer) getValueReflection(decoder, "maxChunkSize", 2));
	                    validate.set((Boolean) getValueReflection(decoder, "validateHeaders", 2));
	                })
	        .post()
	        .uri("/")
	        .send(ByteBufFlux.fromString(Mono.just("bodysample")))
	        .responseContent()
	        .aggregate()
	        .asString()
	        .block(Duration.ofSeconds(30));

	assertThat(channelRef.get()).isNotNull();

	assertThat(chunkSize.get()).as("line length").isEqualTo(789);
	assertThat(validate.get()).as("validate headers").isFalse();
}