use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project robolectric by robolectric.
the class DefaultRequestDirector method createConnectRequest.
/**
* Creates the CONNECT request for tunnelling.
* Called by {@link #createTunnelToTarget createTunnelToTarget}.
*
* @param route the route to establish
* @param context the context for request execution
*
* @return the CONNECT request for tunnelling
*/
protected HttpRequest createConnectRequest(HttpRoute route, HttpContext context) {
// see RFC 2817, section 5.2 and
// INTERNET-DRAFT: Tunneling TCP based protocols through
// Web proxy servers
HttpHost target = route.getTargetHost();
String host = target.getHostName();
int port = target.getPort();
if (port < 0) {
Scheme scheme = connManager.getSchemeRegistry().getScheme(target.getSchemeName());
port = scheme.getDefaultPort();
}
StringBuilder buffer = new StringBuilder(host.length() + 6);
buffer.append(host);
buffer.append(':');
buffer.append(Integer.toString(port));
String authority = buffer.toString();
ProtocolVersion ver = HttpProtocolParams.getVersion(params);
HttpRequest req = new BasicHttpRequest("CONNECT", authority, ver);
return req;
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project TaEmCasa by Dionen.
the class BasicNetworkTest method redirect.
@Test
public void redirect() throws Exception {
for (int i = 300; i <= 399; i++) {
MockHttpStack mockHttpStack = new MockHttpStack();
BasicHttpResponse fakeResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), i, "");
mockHttpStack.setResponseToReturn(fakeResponse);
BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
Request<String> request = buildRequest();
request.setRetryPolicy(mMockRetryPolicy);
doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
try {
httpNetwork.performRequest(request);
} catch (VolleyError e) {
// expected
}
// should not retry 300 responses.
verify(mMockRetryPolicy, never()).retry(any(VolleyError.class));
reset(mMockRetryPolicy);
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project TaEmCasa by Dionen.
the class BasicNetworkTest method unauthorized.
@Test
public void unauthorized() throws Exception {
MockHttpStack mockHttpStack = new MockHttpStack();
BasicHttpResponse fakeResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), 401, "Unauthorized");
mockHttpStack.setResponseToReturn(fakeResponse);
BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
Request<String> request = buildRequest();
request.setRetryPolicy(mMockRetryPolicy);
doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
try {
httpNetwork.performRequest(request);
} catch (VolleyError e) {
// expected
}
// should retry in case it's an auth failure.
verify(mMockRetryPolicy).retry(any(AuthFailureError.class));
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project TaEmCasa by Dionen.
the class BasicNetworkTest method serverError_disableRetries.
@Test
public void serverError_disableRetries() throws Exception {
for (int i = 500; i <= 599; i++) {
MockHttpStack mockHttpStack = new MockHttpStack();
BasicHttpResponse fakeResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), i, "");
mockHttpStack.setResponseToReturn(fakeResponse);
BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
Request<String> request = buildRequest();
request.setRetryPolicy(mMockRetryPolicy);
doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
try {
httpNetwork.performRequest(request);
} catch (VolleyError e) {
// expected
}
// should not retry any 500 error w/ HTTP 500 retries turned off (the default).
verify(mMockRetryPolicy, never()).retry(any(VolleyError.class));
reset(mMockRetryPolicy);
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project TaEmCasa by Dionen.
the class MockHttpClient method execute.
// This is the only one we actually use.
@Override
public HttpResponse execute(HttpUriRequest request, HttpContext context) {
requestExecuted = request;
StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), mStatusCode, "");
HttpResponse response = new BasicHttpResponse(statusLine);
response.setEntity(mResponseEntity);
return response;
}
Aggregations