From 0c3fc722b147a2c056bd2265c75bf4602e2664de Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Fri, 3 Jun 2011 16:46:16 -0300 Subject: [PATCH] enable persistent http connections --- src/main/java/org/scribe/model/Request.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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 */