Skip to content

Commit 0c3fc72

Browse files
enable persistent http connections
1 parent 203cf83 commit 0c3fc72

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/main/java/org/scribe/model/Request.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Request
2727
private HttpURLConnection connection;
2828
private String charset;
2929
private byte[] bytePayload = null;
30+
private boolean connectionKeepAlive = false;
3031

3132
/**
3233
* Creates a new Http Request
@@ -67,7 +68,7 @@ private void createConnection() throws IOException
6768
String effectiveUrl = URLUtils.appendParametersToQueryString(url, querystringParams);
6869
if (connection == null)
6970
{
70-
System.setProperty("http.keepAlive", "false");
71+
System.setProperty("http.keepAlive", connectionKeepAlive ? "true" : "false");
7172
connection = (HttpURLConnection) new URL(effectiveUrl).openConnection();
7273
}
7374
}
@@ -302,6 +303,17 @@ public void setCharset(String charsetName)
302303
this.charset = charsetName;
303304
}
304305

306+
/**
307+
* Sets wether the underlying Http Connection is persistent or not.
308+
*
309+
* @see http://download.oracle.com/javase/1.5.0/docs/guide/net/http-keepalive.html
310+
* @param connectionKeepAlive
311+
*/
312+
public void setConnectionKeepAlive(boolean connectionKeepAlive)
313+
{
314+
this.connectionKeepAlive = connectionKeepAlive;
315+
}
316+
305317
/*
306318
* We need this in order to stub the connection object for test cases
307319
*/

0 commit comments

Comments
 (0)