* There's no need to send content-length header if HttpRequestHandler is going to close the connection right after a response.
* HttpClient sets 'Connection' to 'close' so that the HTTP server closes the connection
This commit is contained in:
parent
ee3440567c
commit
553c4d2df8
@ -90,6 +90,7 @@ public class HttpClient {
|
||||
HttpRequest request = new DefaultHttpRequest(
|
||||
HttpVersion.HTTP_1_1, HttpMethod.GET, uri.toASCIIString());
|
||||
request.addHeader(HttpHeaders.Names.HOST, host);
|
||||
request.addHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
|
||||
CookieEncoder httpCookieEncoder = new CookieEncoder(false);
|
||||
httpCookieEncoder.addCookie("my-cookie", "foo");
|
||||
httpCookieEncoder.addCookie("another-cookie", "bar");
|
||||
|
@ -131,7 +131,12 @@ public class HttpRequestHandler extends SimpleChannelUpstreamHandler {
|
||||
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
|
||||
response.setContent(buf);
|
||||
response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "text/plain; charset=UTF-8");
|
||||
response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(buf.readableBytes()));
|
||||
|
||||
if (!close) {
|
||||
// There's no need to add 'Content-Length' header
|
||||
// if this is the last response.
|
||||
response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(buf.readableBytes()));
|
||||
}
|
||||
|
||||
String cookieString = request.getHeader(HttpHeaders.Names.COOKIE);
|
||||
if (cookieString != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user