diff --git a/src/main/java/org/scribe/model/Request.java b/src/main/java/org/scribe/model/Request.java index 50c0f89..b3a7c66 100644 --- a/src/main/java/org/scribe/model/Request.java +++ b/src/main/java/org/scribe/model/Request.java @@ -27,6 +27,7 @@ class Request private HttpURLConnection connection; private String charset; private byte[] bytePayload = null; + private boolean connectionKeepAlive = false; /** * Creates a new Http Request @@ -67,7 +68,7 @@ class Request String effectiveUrl = URLUtils.appendParametersToQueryString(url, querystringParams); if (connection == null) { - System.setProperty("http.keepAlive", "false"); + System.setProperty("http.keepAlive", connectionKeepAlive ? "true" : "false"); connection = (HttpURLConnection) new URL(effectiveUrl).openConnection(); } } @@ -302,6 +303,17 @@ class Request this.charset = charsetName; } + /** + * Sets wether the underlying Http Connection is persistent or not. + * + * @see http://download.oracle.com/javase/1.5.0/docs/guide/net/http-keepalive.html + * @param connectionKeepAlive + */ + public void setConnectionKeepAlive(boolean connectionKeepAlive) + { + this.connectionKeepAlive = connectionKeepAlive; + } + /* * We need this in order to stub the connection object for test cases */