List of usage examples for com.squareup.okhttp Protocol HTTP_1_1
Protocol HTTP_1_1
To view the source code for com.squareup.okhttp Protocol HTTP_1_1.
Click Source Link
From source file:com.mattermost.service.MattermostService.java
License:Open Source License
public MattermostService(Context context) { this.context = context; String userAgent = context.getResources().getString(R.string.app_user_agent); cookieStore = new WebkitCookieManagerProxy(); client.setProtocols(Arrays.asList(Protocol.HTTP_1_1)); client.setCookieHandler(cookieStore); preferences = context.getSharedPreferences("App", Context.MODE_PRIVATE); }
From source file:com.microsoft.rest.CredentialsTests.java
License:Open Source License
@Test public void basicCredentialsTest() throws Exception { ServiceClient serviceClient = new ServiceClient() { };//from w ww. j ava 2 s .c o m BasicAuthenticationCredentials credentials = new BasicAuthenticationCredentials("user", "pass"); credentials.applyCredentialsFilter(serviceClient.client); serviceClient.getClientInterceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { String header = chain.request().header("Authorization"); Assert.assertEquals("Basic dXNlcjpwYXNz", header); return new Response.Builder().request(chain.request()).code(200).protocol(Protocol.HTTP_1_1) .build(); } }); }
From source file:com.microsoft.rest.CredentialsTests.java
License:Open Source License
@Test public void tokenCredentialsTest() throws Exception { ServiceClient serviceClient = new ServiceClient() { };//from w w w . j a va2s .com TokenCredentials credentials = new TokenCredentials(null, "this_is_a_token"); credentials.applyCredentialsFilter(serviceClient.client); serviceClient.getClientInterceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { String header = chain.request().header("Authorization"); Assert.assertEquals("Bearer this_is_a_token", header); return new Response.Builder().request(chain.request()).code(200).protocol(Protocol.HTTP_1_1) .build(); } }); }
From source file:com.microsoft.rest.RetryHandlerTests.java
License:Open Source License
@Test public void exponentialRetryEndOn501() throws Exception { ServiceClient serviceClient = new ServiceClient() { };/*from w w w. j a va 2s .c om*/ serviceClient.getClientInterceptors().add(new Interceptor() { // Send 408, 500, 502, all retried, with a 501 ending private int[] codes = new int[] { 408, 500, 502, 501 }; private int count = 0; @Override public Response intercept(Chain chain) throws IOException { return new Response.Builder().request(chain.request()).code(codes[count++]) .protocol(Protocol.HTTP_1_1).build(); } }); Response response = serviceClient.client .newCall(new Request.Builder().url("http://localhost").get().build()).execute(); Assert.assertEquals(501, response.code()); }
From source file:com.microsoft.rest.RetryHandlerTests.java
License:Open Source License
@Test public void exponentialRetryMax() throws Exception { ServiceClient serviceClient = new ServiceClient() { };/* w w w. ja v a 2 s . c o m*/ serviceClient.getClientInterceptors().add(new Interceptor() { // Send 500 until max retry is hit private int count = 0; @Override public Response intercept(Chain chain) throws IOException { Assert.assertTrue(count++ < 5); return new Response.Builder().request(chain.request()).code(500).protocol(Protocol.HTTP_1_1) .build(); } }); Response response = serviceClient.client .newCall(new Request.Builder().url("http://localhost").get().build()).execute(); Assert.assertEquals(500, response.code()); }
From source file:com.microsoft.rest.UserAgentTests.java
License:Open Source License
@Test public void defaultUserAgentTests() throws Exception { ServiceClient serviceClient = new ServiceClient() { };/* w ww . j av a2 s .c o m*/ serviceClient.getClientInterceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { String header = chain.request().header("User-Agent"); Assert.assertEquals("AutoRest-Java", header); return new Response.Builder().request(chain.request()).code(200).protocol(Protocol.HTTP_1_1) .build(); } }); }
From source file:com.microsoft.rest.UserAgentTests.java
License:Open Source License
@Test public void customUserAgentTests() throws Exception { ServiceClient serviceClient = new ServiceClient() { };//from w ww.j a v a 2 s . co m serviceClient.getClientInterceptors().add(new UserAgentInterceptor("Awesome")); serviceClient.getClientInterceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { String header = chain.request().header("User-Agent"); Assert.assertEquals("Awesome", header); return new Response.Builder().request(chain.request()).code(200).protocol(Protocol.HTTP_1_1) .build(); } }); }
From source file:com.pangbo.android.thirdframworks.retrofit.Response.java
License:Apache License
/** Create a synthetic successful response with {@code body} as the deserialized body. */ public static <T> Response<T> success(T body) { return success(body, new com.squareup.okhttp.Response.Builder() // .code(200).message("OK").protocol(Protocol.HTTP_1_1) .request(new com.squareup.okhttp.Request.Builder().url("http://localhost").build()).build()); }
From source file:com.pangbo.android.thirdframworks.retrofit.Response.java
License:Apache License
/** * Create a synthetic error response with an HTTP status code of {@code code} and {@code body} * as the error body./*from w w w .j a v a2s. co m*/ */ public static <T> Response<T> error(int code, ResponseBody body) { if (code < 400) throw new IllegalArgumentException("code < 400: " + code); return error(body, new com.squareup.okhttp.Response.Builder() // .code(code).protocol(Protocol.HTTP_1_1) .request(new com.squareup.okhttp.Request.Builder().url("http://localhost").build()).build()); }
From source file:com.parse.ParseOkHttpClientTest.java
License:Open Source License
@Test public void testGetParseResponse() throws IOException { int statusCode = 200; String reasonPhrase = "test reason"; final String content = "test"; final int contentLength = content.length(); final String contentType = "application/json"; String url = "http://www.parse.com/"; Request request = new Request.Builder().url(url).build(); Response okHttpResponse = new Response.Builder().request(request).protocol(Protocol.HTTP_1_1) .code(statusCode).message(reasonPhrase).body(new ResponseBody() { @Override// w w w. ja va 2 s .c o m public MediaType contentType() { return MediaType.parse(contentType); } @Override public long contentLength() throws IOException { return contentLength; } @Override public BufferedSource source() throws IOException { Buffer buffer = new Buffer(); buffer.write(content.getBytes()); return buffer; } }).build(); ParseOkHttpClient parseClient = new ParseOkHttpClient(10000, null); ParseHttpResponse parseResponse = parseClient.getResponse(okHttpResponse); // Verify status code assertEquals(statusCode, parseResponse.getStatusCode()); // Verify reason phrase assertEquals(reasonPhrase, parseResponse.getReasonPhrase()); // Verify content length assertEquals(contentLength, parseResponse.getTotalSize()); // Verify content assertArrayEquals(content.getBytes(), ParseIOUtils.toByteArray(parseResponse.getContent())); }