1 /* 2 * Copyright (C) 2014 Square, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.squareup.okhttp; 17 18 import java.io.IOException; 19 20 public interface Callback { 21 /** 22 * Called when the request could not be executed due to cancellation, a 23 * connectivity problem or timeout. Because networks can fail during an 24 * exchange, it is possible that the remote server accepted the request 25 * before the failure. 26 */ 27 void onFailure(Request request, IOException e); 28 29 /** 30 * Called when the HTTP response was successfully returned by the remote 31 * server. The callback may proceed to read the response body with {@link 32 * Response#body}. The response is still live until its response body is 33 * closed with {@code response.body().close()}. The recipient of the callback 34 * may even consume the response body on another thread. 35 * 36 * <p>Note that transport-layer success (receiving a HTTP response code, 37 * headers and body) does not necessarily indicate application-layer 38 * success: {@code response} may still indicate an unhappy HTTP response 39 * code like 404 or 500. 40 */ 41 void onResponse(Response response) throws IOException; 42 } 43