Sending DefaultFullHttpRequest with Reactor Netty HttpClient

时间:2017-06-09 12:44:54

标签: netty reactor-netty

I am attempting to send a large message to a Reactor-Netty HttpServer. The message is 1511 bytes and is written successfully according to the HttpClient logging, however only 1024 bytes is read on the server side. This is because there is no Content-Length in the header.

Reactor-Netty has a few send options, the ones applicable for my post are either send or sendObject. The send method only offers the option to send a ByteBuf, and with DefaultFullHttpRequest not offering a way to convert to a ByteBuf, I can't include the headers.

ByteBuf reqContent = getTestRequest();
DefaultFullHttpRequest reqHeader = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, url, reqContent);
ByteBuf headers = Unpooled.wrappedBuffer(reqHeader.headers().toString().getBytes());
client.post(url, clientRequest -> clientRequest.send(Flux.just(headers))).subscribe();

client.post(url, clientRequest -> clientRequest.send(Flux.just(reqHeader.content()))).subscribe(httpClientResponse -> log.debug("Successful" + httpClientResponse.status()),throwable -> log.error("exception " + throwable));

I do not see where to set the content length, and if I send an Object the I see the headers written twice:

Once as I see when I only send the content

14:39:46.645 [reactor-http-nio-4] DEBUG r.i.n.c.ChannelOperationsHandler - [id: 0x85f9df60, L:/127.0.0.1:57054 - R:localhost/127.0.0.1:8092] Writing object DefaultHttpRequest(decodeResult: success, version: HTTP/1.1) POST /xmlvend HTTP/1.1 user-agent: ReactorNetty/0.6.3.RELEASE transfer-encoding: chunked host: localhost:8092 accept: /

Then again with the content-length

14:39:46.650 [reactor-http-nio-4] DEBUG r.i.n.c.ChannelOperationsHandler - [id: 0x85f9df60, L:/127.0.0.1:57054 - R:localhost/127.0.0.1:8092] Writing object DefaultFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: UnpooledHeapByteBuf(ridx: 0, widx: 1511, cap: 1511/1511)) POST /xmlvend HTTP/1.1 Content-Length: 1511

is there no way to send the FullHttpRequest out using reactor-netty, surely I don't have to go the normal netty way of creating a socket etc.

thanks

0 个答案:

没有答案
相关问题