use of org.apache.http.params.HttpParams in project playn by threerings.
the class AndroidHttpClient method newInstance.
/**
* Create a new HttpClient with reasonable defaults (which you can update).
*
* @param userAgent to report in your HTTP requests.
* @return AndroidHttpClient for you to use for all your requests.
*/
public static AndroidHttpClient newInstance(String userAgent) {
HttpParams params = new BasicHttpParams();
// Turn off stale checking. Our connections break all the time anyway,
// and it's not worth it to pay the penalty of checking every time.
HttpConnectionParams.setStaleCheckingEnabled(params, false);
// Default connection and socket timeout of 20 seconds. Tweak to taste.
HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
HttpConnectionParams.setSoTimeout(params, 20 * 1000);
HttpConnectionParams.setSocketBufferSize(params, 8192);
// Don't handle redirects -- return them to the caller. Our code
// often wants to re-POST after a redirect, which we must do ourselves.
HttpClientParams.setRedirecting(params, false);
// Set the specified user agent and register standard protocols.
HttpProtocolParams.setUserAgent(params, userAgent);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);
// parameters without the funny call-a-static-method dance.
return new AndroidHttpClient(manager, params);
}
use of org.apache.http.params.HttpParams in project undertow by undertow-io.
the class HttpContinueAcceptingHandlerTestCase method testHttpContinueAccepted.
@Test
public void testHttpContinueAccepted() throws IOException {
accept = true;
String message = "My HTTP Request!";
HttpParams httpParams = new BasicHttpParams();
httpParams.setParameter("http.protocol.wait-for-continue", Integer.MAX_VALUE);
TestHttpClient client = new TestHttpClient();
client.setParams(httpParams);
try {
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/path");
post.addHeader("Expect", "100-continue");
post.setEntity(new StringEntity(message));
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals(message, HttpClientUtils.readResponse(result));
} finally {
client.getConnectionManager().shutdown();
}
}
use of org.apache.http.params.HttpParams in project undertow by undertow-io.
the class HttpContinueConduitWrappingHandlerTestCase method testHttpContinueAcceptedWithChunkedRequest.
//UNDERTOW-162
@Test
public void testHttpContinueAcceptedWithChunkedRequest() throws IOException {
accept = true;
String message = "My HTTP Request!";
HttpParams httpParams = new BasicHttpParams();
httpParams.setParameter("http.protocol.wait-for-continue", Integer.MAX_VALUE);
TestHttpClient client = new TestHttpClient();
client.setParams(httpParams);
try {
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/path");
post.addHeader("Expect", "100-continue");
post.setEntity(new StringEntity(message) {
@Override
public long getContentLength() {
return -1;
}
});
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals(message, HttpClientUtils.readResponse(result));
} finally {
client.getConnectionManager().shutdown();
}
}
use of org.apache.http.params.HttpParams in project undertow by undertow-io.
the class HttpContinueConduitWrappingHandlerTestCase method testHttpContinueRejected.
@Test
public void testHttpContinueRejected() throws IOException {
accept = false;
String message = "My HTTP Request!";
HttpParams httpParams = new BasicHttpParams();
httpParams.setParameter("http.protocol.wait-for-continue", Integer.MAX_VALUE);
TestHttpClient client = new TestHttpClient();
client.setParams(httpParams);
try {
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/path");
post.addHeader("Expect", "100-continue");
post.setEntity(new StringEntity(message));
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.EXPECTATION_FAILED, result.getStatusLine().getStatusCode());
} finally {
client.getConnectionManager().shutdown();
}
}
use of org.apache.http.params.HttpParams in project undertow by undertow-io.
the class HttpContinueConduitWrappingHandlerTestCase method testHttpContinueAccepted.
@Test
public void testHttpContinueAccepted() throws IOException {
accept = true;
String message = "My HTTP Request!";
HttpParams httpParams = new BasicHttpParams();
httpParams.setParameter("http.protocol.wait-for-continue", Integer.MAX_VALUE);
TestHttpClient client = new TestHttpClient();
client.setParams(httpParams);
try {
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/path");
post.addHeader("Expect", "100-continue");
post.setEntity(new StringEntity(message));
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals(message, HttpClientUtils.readResponse(result));
} finally {
client.getConnectionManager().shutdown();
}
}
Aggregations