I have created an HTTPServer in Netty with the following handler:
public class HttpRouterServerHandler extends SimpleChannelInboundHandler<HttpRequest> {
public void channelRead0(ChannelHandlerContext ctx, HttpRequest req) {
if (HttpUtil.is100ContinueExpected(req)) {
ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE));
return;
}
System.out.println(req.toString());
HttpResponse res = /* create the response here */
flushResponse(ctx, req, res);
}
I send the PUT request in Python using http.client:
json_data = /* constructJSON content */
connection = http.client.HTTPConnection("localhost", 8080)
connection.request("PUT", "/proto/api/send", json_data)
response = self.connection.getresponse()
connection.close()
For some reason, I can't get the BODY of the request (the json content). The reason seems to be that my HttpRequest
is not a FullHttpRequest
, so I can't get its content()
It I print the content of my request, I have something like:
DefaultHttpRequest(decodeResult: success, version: HTTP/1.1)
PUT /proto/api/send HTTP/1.1
Host: localhost:8080
Accept-Encoding: identity
content-length: 47
Also I tried to replace the HttpRequest by FullHttpRequest for my handler, but in this case the Netty server does not respond anymore, which lead to an exception in Python:
public class HttpRouterServerHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) {
if (HttpUtil.is100ContinueExpected(req)) {
ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE));
return;
}
System.out.println(req.toString());
HttpResponse res = /* create the response here */
flushResponse(ctx, req, res);
}
Where is my mistake?