Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhaval201279/95429d53915631f84fad745d1ebeb4fd to your computer and use it in GitHub Desktop.
Save dhaval201279/95429d53915631f84fad745d1ebeb4fd to your computer and use it in GitHub Desktop.
Http client config with custom defined keep alive strategy
private ConnectionKeepAliveStrategy connectionKeepAliveStrategy() {
return new DefaultConnectionKeepAliveStrategy() {
@Override
public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) {
long keepAliveDuration = super.getKeepAliveDuration(response, context);
if (keepAliveDuration < 0) {
keepAliveDuration = DEFAULT_KEEP_ALIVE_TIME_MILLIS;
} else if (keepAliveDuration > MAX_KEEP_ALIVE_TIME_MILLIS) {
keepAliveDuration = MAX_KEEP_ALIVE_TIME_MILLIS;
}
return keepAliveDuration;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment