private static Response stripBody(Response response) { return response != null && response.body() != null ? response.newBuilder().body(null).build() : response; }
private static Response stripBody(Response response) { return response != null && response.body() != null ? response.newBuilder().body(null).build() : response; }
private static final Interceptor REWRITE_CACHE_CONTROL_INTERCEPTOR = new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Response originalResponse = chain.proceed(chain.request()); return originalResponse.newBuilder() .header("Cache-Control", String.format("max-age=%d, only-if-cached, max-stale=%d", 120, 0)) .build(); } };
.addNetworkInterceptor(chain -> { Response originalResponse = chain.proceed(chain.request()); return originalResponse.newBuilder() .body(new ProgressResponseBody(originalResponse.body(), progressListener)) .build();
@Override public Response intercept(Chain chain) throws IOException { Response original=chain.proceed(chain.request()); Response.Builder b=original .newBuilder() .body( new ProgressResponseBody(original.body(), progressListener)); return(b.build()); } };
@Override public Response intercept(Chain chain) throws IOException { Response original=chain.proceed(chain.request()); Response.Builder b=original .newBuilder() .body( new ProgressResponseBody(original.body(), progressListener)); return(b.build()); } };
@Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); Response response = chain.proceed(request); return response.newBuilder() .body(new OkHttpProgressResponseBody(request.url(), response.body(), listener)) .build(); } };
static Response withServedDateHeader(Response response) throws IOException { return response.newBuilder() .addHeader(CACHE_SERVED_DATE_HEADER, HttpDate.format(new Date())) .build(); }
@Override public Response intercept(Chain chain) throws IOException { Response originalResponse = chain.proceed(chain.request()); return originalResponse.newBuilder() .body(new ResponseProgressBody(originalResponse.body(), request.getDownloadProgressListener())) .build(); } }).build();
@Override public Response intercept(Chain chain) throws IOException { Response originalResponse = chain.proceed(chain.request()); return originalResponse.newBuilder() .body(new ResponseProgressBody(originalResponse.body(), request.getDownloadProgressListener())) .build(); } }).build();
@Override public Response intercept(Chain chain) throws IOException { Response originalResponse = chain.proceed(chain.request()); return originalResponse.newBuilder() .body(new ResponseProgressBody(originalResponse.body(), request.getDownloadProgressListener())) .build(); } }).build();
@Override public Response intercept(Chain chain) throws IOException { Response originalResponse = chain.proceed(chain.request()); return originalResponse.newBuilder() .body(new ResponseProgressBody(originalResponse.body(), request.getDownloadProgressListener())) .build(); } }).build();
@Override public Response intercept(Chain chain) throws IOException { Response originalResponse = chain.proceed(chain.request()); return originalResponse.newBuilder() .body(new ResponseProgressBody(originalResponse.body(), request.getDownloadProgressListener())) .build(); } }).build();
@Override public Response intercept(Chain chain) throws IOException { Response originalResponse = chain.proceed(chain.request()); return originalResponse.newBuilder() .body(new ResponseProgressBody(originalResponse.body(), request.getDownloadProgressListener())) .build(); } }).build();
return response.newBuilder() .body(new RealResponseBody(contentType, contentLength, Okio.buffer(cacheWritingSource))) .build();
public void processResponse(Response response) { try { if (!response.isSuccessful()) { listener.onFailure(this, null, response); return; } ResponseBody body = response.body(); //noinspection ConstantConditions main body is never null MediaType contentType = body.contentType(); if (!isEventStream(contentType)) { listener.onFailure(this, new IllegalStateException("Invalid content-type: " + contentType), response); return; } // Replace the body with an empty one so the callbacks can't see real data. response = response.newBuilder().body(Util.EMPTY_RESPONSE).build(); ServerSentEventReader reader = new ServerSentEventReader(body.source(), this); try { listener.onOpen(this, response); while (reader.processNextEvent()) { } } catch (Exception e) { listener.onFailure(this, e, response); return; } listener.onClosed(this); } finally { response.close(); } }
/** * Creates an {@link java.net.HttpURLConnection} of the correct subclass from the supplied OkHttp * {@link Response}. */ static HttpURLConnection createJavaUrlConnectionForCachePut(Response okResponse) { okResponse = okResponse.newBuilder() .body(null) .headers(withSyntheticHeaders(okResponse)) .build(); Request request = okResponse.request(); // Create an object of the correct class in case the ResponseCache uses instanceof. if (request.isHttps()) { return new CacheHttpsURLConnection(new CacheHttpURLConnection(okResponse)); } else { return new CacheHttpURLConnection(okResponse); } }
Response.Builder responseBuilder = networkResponse.newBuilder() .request(userRequest);
rawResponse = rawResponse.newBuilder() .body(new NoContentResponseBody(rawBody.contentType(), rawBody.contentLength())) .build();
@Test public void cachedResponseDoesNotDispatchToStats() throws Exception { responses.add(responseOf(ResponseBody.create(null, new byte[10])) .newBuilder() .cacheResponse(responseOf(null)) .build()); Action action = TestUtils.mockAction(URI_KEY_1, URI_1); final CountDownLatch latch = new CountDownLatch(1); networkHandler.load(picasso, action.request, new RequestHandler.Callback() { @Override public void onSuccess(Result result) { verifyZeroInteractions(stats); latch.countDown(); } @Override public void onError(@NonNull Throwable t) { throw new AssertionError(t); } }); assertThat(latch.await(10, SECONDS)).isTrue(); }