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.facebook.buck.slb.SingleUriServiceTest.java
License:Apache License
@Test public void testClientIsCalledWithFullUrl() throws IOException, InterruptedException { OkHttpClient mockClient = EasyMock.createMock(OkHttpClient.class); String path = "my/super/path"; Request.Builder request = new Request.Builder().url(SERVER + path).get(); Call mockCall = EasyMock.createMock(Call.class); EasyMock.expect(mockClient.newCall(EasyMock.anyObject(Request.class))).andReturn(mockCall); Response response = new Response.Builder().message("my super response").request(request.build()) .protocol(Protocol.HTTP_1_1).code(200).build(); EasyMock.expect(mockCall.execute()).andReturn(response); EasyMock.replay(mockCall, mockClient); try (SingleUriService service = new SingleUriService(SERVER, mockClient)) { service.makeRequest(path, request); }// w w w .j av a 2 s . co m }
From source file:com.facebook.stetho.okhttp.StethoInterceptorTest.java
License:Open Source License
@Test public void testHappyPath() throws IOException { InOrder inOrder = Mockito.inOrder(mMockEventReporter); hookAlmostRealRequestWillBeSent(mMockEventReporter); ByteArrayOutputStream capturedOutput = hookAlmostRealInterpretResponseStream(mMockEventReporter); Uri requestUri = Uri.parse("http://www.facebook.com/nowhere"); String requestText = "Test input"; Request request = new Request.Builder().url(requestUri.toString()) .method("POST", RequestBody.create(MediaType.parse("text/plain"), requestText)).build(); String originalBodyData = "Success!"; Response reply = new Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(200) .body(ResponseBody.create(MediaType.parse("text/plain"), originalBodyData)).build(); Response filteredResponse = mInterceptor.intercept(new SimpleTestChain(request, reply, null)); inOrder.verify(mMockEventReporter).isEnabled(); inOrder.verify(mMockEventReporter).requestWillBeSent(any(NetworkEventReporter.InspectorRequest.class)); inOrder.verify(mMockEventReporter).dataSent(anyString(), eq(requestText.length()), eq(requestText.length()));/*from ww w . j a va 2 s. co m*/ inOrder.verify(mMockEventReporter) .responseHeadersReceived(any(NetworkEventReporter.InspectorResponse.class)); String filteredResponseString = filteredResponse.body().string(); String interceptedOutput = capturedOutput.toString(); inOrder.verify(mMockEventReporter).dataReceived(anyString(), anyInt(), anyInt()); inOrder.verify(mMockEventReporter).responseReadFinished(anyString()); assertEquals(originalBodyData, filteredResponseString); assertEquals(originalBodyData, interceptedOutput); inOrder.verifyNoMoreInteractions(); }
From source file:com.groupon.mesos.util.HttpProtocolSender.java
License:Apache License
public HttpProtocolSender(final UPID sender) { this.client = new OkHttpClient(); client.setProtocols(ImmutableList.of(Protocol.HTTP_1_1)); this.sender = sender.asString(); }
From source file:com.jaspersoft.android.jaspermobile.webview.intercept.okhttp.OkHttpWebResourceInterceptorTest.java
License:Open Source License
private void givenOkHttpClient() throws Exception { okRequest = new Request.Builder().url(ANY_URL).build(); okResponse = new Response.Builder().protocol(Protocol.HTTP_1_1).request(okRequest).code(200).build(); when(okCall.execute()).thenReturn(okResponse); when(okClient.newCall(any(Request.class))).thenReturn(okCall); }
From source file:com.jaspersoft.android.jaspermobile.webview.intercept.okhttp.OkResponseMapperTest.java
License:Open Source License
private void givenResponse() { Request okRequest = new Request.Builder().url(ANY_URL).build(); okResponse = new Response.Builder().protocol(Protocol.HTTP_1_1).request(okRequest).message("OK") .addHeader(CONTENT_TYPE, "application/json").addHeader(CONTENT_ENCODING, "utf-8").code(200).build(); }
From source file:com.kubeiwu.easyandroid.easyhttp.core.retrofit.KOkHttpCall.java
License:Apache License
private Response<T> execCacheRequest(Request request) { if (responseConverter instanceof GsonConverter) { GsonConverter<T> converter = (GsonConverter<T>) responseConverter; Cache cache = converter.getCache(); if (cache == null) { return null; }/* www. j a v a 2 s .c om*/ Entry entry = cache.get(request.urlString());// ?entry if (entry == null) { return null; } if (entry.isExpired()) {// return null; } if (entry.data != null) {// ? MediaType contentType = MediaType.parse(entry.mimeType); byte[] bytes = entry.data; try { com.squareup.okhttp.Response rawResponse = new com.squareup.okhttp.Response.Builder()// .code(200).request(request).protocol(Protocol.HTTP_1_1) .body(ResponseBody.create(contentType, bytes)).build(); return parseResponse(rawResponse, request); } catch (Exception e) { e.printStackTrace(); } } } return null; }
From source file:com.kubeiwu.easyandroid.easyhttp.core.retrofit.Response.java
License:Apache License
/** * TODO/*from w w w. j a v a 2s. c o m*/ */ public static <T> Response<T> success(T body) { return success(body, new com.squareup.okhttp.Response.Builder() // .code(200).protocol(Protocol.HTTP_1_1) .request(new com.squareup.okhttp.Request.Builder().url(HttpUrl.parse("http://localhost")).build()) .build()); }
From source file:com.kubeiwu.easyandroid.easyhttp.core.retrofit.Response.java
License:Apache License
/** * TODO//w w w . ja v a2 s .c o m */ public static <T> Response<T> error(int code, ResponseBody body) { return error(body, new com.squareup.okhttp.Response.Builder() // .code(code).protocol(Protocol.HTTP_1_1) .request(new com.squareup.okhttp.Request.Builder().url(HttpUrl.parse("http://localhost")).build()) .build()); }
From source file:com.lobobrowser.LoboBrowser.java
License:Open Source License
/** * Initializes the global URLStreamHandlerFactory. * <p>//w ww . j av a 2 s.co m * This method is invoked by {@link #init(boolean, boolean)}. */ public static void initProtocols(final SSLSocketFactory sslSocketFactory) { // Configure URL protocol handlers final PlatformStreamHandlerFactory factory = PlatformStreamHandlerFactory.getInstance(); URL.setURLStreamHandlerFactory(factory); final OkHttpClient okHttpClient = new OkHttpClient(); final ArrayList<Protocol> protocolList = new ArrayList<>(2); protocolList.add(Protocol.HTTP_1_1); protocolList.add(Protocol.HTTP_2); okHttpClient.setProtocols(protocolList); okHttpClient.setConnectTimeout(100, TimeUnit.SECONDS); // HttpsURLConnection.setDefaultSSLSocketFactory(sslSocketFactory); okHttpClient.setSslSocketFactory(sslSocketFactory); okHttpClient.setFollowRedirects(false); okHttpClient.setFollowSslRedirects(false); factory.addFactory(new OkUrlFactory(okHttpClient)); factory.addFactory(new LocalStreamHandlerFactory()); }
From source file:com.magnet.max.android.rest.qos.internal.CachedResponse.java
License:Apache License
public Protocol getProtocolEnum() { if (null != protocol) { try {//from ww w. ja va 2 s . c om return Protocol.get(protocol); } catch (IOException e) { e.printStackTrace(); } } return Protocol.HTTP_1_1; }