类 io.netty.handler.codec.http.HttpObjectDecoder 源码实例Demo

下面列出了怎么用 io.netty.handler.codec.http.HttpObjectDecoder 的API类实例代码及写法,或者点击链接到github查看源代码。


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);
    }
}
 
源代码2 项目: reactor-netty   文件: HttpServerTests.java

@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();
}
 
源代码3 项目: reactor-netty   文件: HttpClientTest.java

@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();
}
 
 同包方法