당신은 추가 "- 살아 계속 연결"HttpResponseInterceptor을 추가 할 수 있습니다 문서 HttpComponents Custom stratagey
참조 섹션입니다 필요한 경우 "Connection : close"헤더를 설정 한 org.apache.http.protocol.ResponseConnControl의 평가.
class ResposeKeepAliveHeaderMod implements HttpResponseInterceptor {
@Override
public void process(HttpResponse response, HttpContext context)
throws HttpException, IOException {
final Header explicit = response.getFirstHeader(HTTP.CONN_DIRECTIVE);
if (explicit != null && HTTP.CONN_CLOSE.equalsIgnoreCase(explicit.getValue())) {
// Connection persistence explicitly disabled
return;
}else{
// "Connection: Keep-Alive" and "Keep-Alive: timeout=x, max=y"
response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
response.setHeader(HTTP.CONN_KEEP_ALIVE, "timeout=30, max=100");
}
}
}
당신은 ResponseConnControl 후, HttpProcessor이를 추가해야합니다
HttpProcessor httpProcessor = HttpProcessorBuilder.create()
//.addFirst(new RequestTrace())
.add(new ResponseDate())
//.add(new ResponseServer("MyServer-HTTP/1.1"))
.add(new ResponseContent())
.add(new ResponseConnControl())
.addLast(new ResposeKeepAliveHeaderMod())
.build();
그런 다음 서버를 구축 :
final HttpServer server = ServerBootstrap.bootstrap()
.setListenerPort(9090)
.setHttpProcessor(httpProcessor)
.setSocketConfig(socketConfig)
.setExceptionLogger(new StdErrorExceptionLogger())
.setHandlerMapper(handle_map)
.create();
의
가능한 중복 [요청 헤더를 설정, 추가하는 방법을 HttpClient?] (http://stackoverflow.com/questions/13743205/how-to-add-set-and-get-header-in-request-of-httpclient) –
이것은 http : //와 중복되지 않습니다. stackoverflow.com/questions/13743205/how-to-add-se HttpClient가 아니라 서버 측에 대해 묻고 있습니다 (11 개월 전 게시했습니다). –