1c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath/* 2c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath * Copyright (C) 2011 The Android Open Source Project 3c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath * 4c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath * Licensed under the Apache License, Version 2.0 (the "License"); 5c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath * you may not use this file except in compliance with the License. 6c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath * You may obtain a copy of the License at 7c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath * 8c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath * http://www.apache.org/licenses/LICENSE-2.0 9c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath * 10c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath * Unless required by applicable law or agreed to in writing, software 11c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath * distributed under the License is distributed on an "AS IS" BASIS, 12c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath * See the License for the specific language governing permissions and 14c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath * limitations under the License. 15c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath */ 162231db3e6bb54447a9b14cf004a6cb03c373651cjwilsonpackage com.squareup.okhttp; 17c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath 1854cf3446000fdcf88a9e62724f7deb0282e98da1jwilson/** The source of an HTTP response. */ 19c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamathpublic enum ResponseSource { 20c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath 2154cf3446000fdcf88a9e62724f7deb0282e98da1jwilson /** The response was returned from the local cache. */ 2254cf3446000fdcf88a9e62724f7deb0282e98da1jwilson CACHE, 23c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath 2454cf3446000fdcf88a9e62724f7deb0282e98da1jwilson /** 2554cf3446000fdcf88a9e62724f7deb0282e98da1jwilson * The response is available in the cache but must be validated with the 2654cf3446000fdcf88a9e62724f7deb0282e98da1jwilson * network. The cache result will be used if it is still valid; otherwise 2754cf3446000fdcf88a9e62724f7deb0282e98da1jwilson * the network's response will be used. 2854cf3446000fdcf88a9e62724f7deb0282e98da1jwilson */ 2954cf3446000fdcf88a9e62724f7deb0282e98da1jwilson CONDITIONAL_CACHE, 30c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath 3154cf3446000fdcf88a9e62724f7deb0282e98da1jwilson /** The response was returned from the network. */ 323c938a3f6b61ce5e2dba0d039b03fe73b89fd26cNeil Fuller NETWORK, 333c938a3f6b61ce5e2dba0d039b03fe73b89fd26cNeil Fuller 343c938a3f6b61ce5e2dba0d039b03fe73b89fd26cNeil Fuller /** 353c938a3f6b61ce5e2dba0d039b03fe73b89fd26cNeil Fuller * The request demanded a cached response that the cache couldn't satisfy. 363c938a3f6b61ce5e2dba0d039b03fe73b89fd26cNeil Fuller * This yields a 504 (Gateway Timeout) response as specified by 373c938a3f6b61ce5e2dba0d039b03fe73b89fd26cNeil Fuller * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.4. 383c938a3f6b61ce5e2dba0d039b03fe73b89fd26cNeil Fuller */ 393c938a3f6b61ce5e2dba0d039b03fe73b89fd26cNeil Fuller NONE; 40c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath 4154cf3446000fdcf88a9e62724f7deb0282e98da1jwilson public boolean requiresConnection() { 4254cf3446000fdcf88a9e62724f7deb0282e98da1jwilson return this == CONDITIONAL_CACHE || this == NETWORK; 4354cf3446000fdcf88a9e62724f7deb0282e98da1jwilson } 443c938a3f6b61ce5e2dba0d039b03fe73b89fd26cNeil Fuller 453c938a3f6b61ce5e2dba0d039b03fe73b89fd26cNeil Fuller public boolean usesCache() { 463c938a3f6b61ce5e2dba0d039b03fe73b89fd26cNeil Fuller return this == CACHE || this == CONDITIONAL_CACHE; 473c938a3f6b61ce5e2dba0d039b03fe73b89fd26cNeil Fuller } 48c3f6f16bd4a2338e88275641b9f2f56e816ca377Narayan Kamath} 49