mirror of
https://github.com/square/okhttp.git
synced 2025-08-08 23:42:08 +03:00
Add connection, cache, and platform subpackages.
This commit is contained in:
@@ -28,14 +28,14 @@ import java.util.logging.Logger;
|
|||||||
import javax.net.ssl.SSLSocket;
|
import javax.net.ssl.SSLSocket;
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
import okhttp3.Protocol;
|
import okhttp3.Protocol;
|
||||||
import okhttp3.internal.Platform;
|
|
||||||
import okhttp3.internal.Util;
|
import okhttp3.internal.Util;
|
||||||
|
import okhttp3.internal.platform.Platform;
|
||||||
import okhttp3.internal.tls.SslClient;
|
import okhttp3.internal.tls.SslClient;
|
||||||
import okio.BufferedSink;
|
import okio.BufferedSink;
|
||||||
import okio.Okio;
|
import okio.Okio;
|
||||||
import okio.Source;
|
import okio.Source;
|
||||||
|
|
||||||
import static okhttp3.internal.Platform.INFO;
|
import static okhttp3.internal.platform.Platform.INFO;
|
||||||
|
|
||||||
/** A basic SPDY/HTTP_2 server that serves the contents of a local directory. */
|
/** A basic SPDY/HTTP_2 server that serves the contents of a local directory. */
|
||||||
public final class FramedServer extends FramedConnection.Listener {
|
public final class FramedServer extends FramedConnection.Listener {
|
||||||
|
@@ -59,7 +59,6 @@ import okhttp3.Protocol;
|
|||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.internal.NamedRunnable;
|
import okhttp3.internal.NamedRunnable;
|
||||||
import okhttp3.internal.Platform;
|
|
||||||
import okhttp3.internal.Util;
|
import okhttp3.internal.Util;
|
||||||
import okhttp3.internal.framed.ErrorCode;
|
import okhttp3.internal.framed.ErrorCode;
|
||||||
import okhttp3.internal.framed.FramedConnection;
|
import okhttp3.internal.framed.FramedConnection;
|
||||||
@@ -67,6 +66,7 @@ import okhttp3.internal.framed.FramedStream;
|
|||||||
import okhttp3.internal.framed.Header;
|
import okhttp3.internal.framed.Header;
|
||||||
import okhttp3.internal.framed.Settings;
|
import okhttp3.internal.framed.Settings;
|
||||||
import okhttp3.internal.http.HttpMethod;
|
import okhttp3.internal.http.HttpMethod;
|
||||||
|
import okhttp3.internal.platform.Platform;
|
||||||
import okhttp3.internal.ws.RealWebSocket;
|
import okhttp3.internal.ws.RealWebSocket;
|
||||||
import okhttp3.internal.ws.WebSocketProtocol;
|
import okhttp3.internal.ws.WebSocketProtocol;
|
||||||
import okhttp3.ws.WebSocketListener;
|
import okhttp3.ws.WebSocketListener;
|
||||||
|
@@ -70,7 +70,7 @@ public class AndroidShimResponseCache extends ResponseCache {
|
|||||||
// The URLConnection is not cacheable or could not be converted. Stop.
|
// The URLConnection is not cacheable or could not be converted. Stop.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
okhttp3.internal.http.CacheRequest okCacheRequest =
|
okhttp3.internal.cache.CacheRequest okCacheRequest =
|
||||||
delegate.internalCache.put(okResponse);
|
delegate.internalCache.put(okResponse);
|
||||||
if (okCacheRequest == null) {
|
if (okCacheRequest == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@@ -25,9 +25,9 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.internal.InternalCache;
|
import okhttp3.internal.cache.CacheRequest;
|
||||||
import okhttp3.internal.http.CacheRequest;
|
import okhttp3.internal.cache.CacheStrategy;
|
||||||
import okhttp3.internal.http.CacheStrategy;
|
import okhttp3.internal.cache.InternalCache;
|
||||||
import okio.Okio;
|
import okio.Okio;
|
||||||
import okio.Sink;
|
import okio.Sink;
|
||||||
|
|
||||||
|
@@ -44,12 +44,12 @@ import okhttp3.Response;
|
|||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
import okhttp3.internal.Internal;
|
import okhttp3.internal.Internal;
|
||||||
import okhttp3.internal.JavaNetHeaders;
|
import okhttp3.internal.JavaNetHeaders;
|
||||||
import okhttp3.internal.Platform;
|
|
||||||
import okhttp3.internal.Util;
|
import okhttp3.internal.Util;
|
||||||
import okhttp3.internal.http.CacheRequest;
|
import okhttp3.internal.cache.CacheRequest;
|
||||||
|
import okhttp3.internal.http.HttpHeaders;
|
||||||
import okhttp3.internal.http.HttpMethod;
|
import okhttp3.internal.http.HttpMethod;
|
||||||
import okhttp3.internal.http.OkHeaders;
|
|
||||||
import okhttp3.internal.http.StatusLine;
|
import okhttp3.internal.http.StatusLine;
|
||||||
|
import okhttp3.internal.platform.Platform;
|
||||||
import okio.BufferedSource;
|
import okio.BufferedSource;
|
||||||
import okio.Okio;
|
import okio.Okio;
|
||||||
import okio.Sink;
|
import okio.Sink;
|
||||||
@@ -162,11 +162,11 @@ public final class JavaApiConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Headers varyHeaders(URLConnection urlConnection, Headers responseHeaders) {
|
private static Headers varyHeaders(URLConnection urlConnection, Headers responseHeaders) {
|
||||||
if (OkHeaders.hasVaryAll(responseHeaders)) {
|
if (HttpHeaders.hasVaryAll(responseHeaders)) {
|
||||||
// "*" means that this will be treated as uncacheable anyway.
|
// "*" means that this will be treated as uncacheable anyway.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Set<String> varyFields = OkHeaders.varyFields(responseHeaders);
|
Set<String> varyFields = HttpHeaders.varyFields(responseHeaders);
|
||||||
if (varyFields.isEmpty()) {
|
if (varyFields.isEmpty()) {
|
||||||
return new Headers.Builder().build();
|
return new Headers.Builder().build();
|
||||||
}
|
}
|
||||||
@@ -212,11 +212,11 @@ public final class JavaApiConverter {
|
|||||||
// Build a cache request for the response to use.
|
// Build a cache request for the response to use.
|
||||||
Headers responseHeaders = createHeaders(javaResponse.getHeaders());
|
Headers responseHeaders = createHeaders(javaResponse.getHeaders());
|
||||||
Headers varyHeaders;
|
Headers varyHeaders;
|
||||||
if (OkHeaders.hasVaryAll(responseHeaders)) {
|
if (HttpHeaders.hasVaryAll(responseHeaders)) {
|
||||||
// "*" means that this will be treated as uncacheable anyway.
|
// "*" means that this will be treated as uncacheable anyway.
|
||||||
varyHeaders = new Headers.Builder().build();
|
varyHeaders = new Headers.Builder().build();
|
||||||
} else {
|
} else {
|
||||||
varyHeaders = OkHeaders.varyHeaders(request.headers(), responseHeaders);
|
varyHeaders = HttpHeaders.varyHeaders(request.headers(), responseHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
Request cacheRequest = new Request.Builder()
|
Request cacheRequest = new Request.Builder()
|
||||||
@@ -519,7 +519,7 @@ public final class JavaApiConverter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long contentLength() {
|
public long contentLength() {
|
||||||
return OkHeaders.contentLength(okHeaders);
|
return HttpHeaders.contentLength(okHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public BufferedSource source() {
|
@Override public BufferedSource source() {
|
||||||
|
@@ -29,13 +29,12 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.net.ssl.HostnameVerifier;
|
import javax.net.ssl.HostnameVerifier;
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
|
||||||
import okhttp3.AbstractResponseCache;
|
import okhttp3.AbstractResponseCache;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.OkUrlFactory;
|
import okhttp3.OkUrlFactory;
|
||||||
import okhttp3.RecordingHostnameVerifier;
|
import okhttp3.RecordingHostnameVerifier;
|
||||||
import okhttp3.internal.Internal;
|
import okhttp3.internal.Internal;
|
||||||
import okhttp3.internal.InternalCache;
|
import okhttp3.internal.cache.InternalCache;
|
||||||
import okhttp3.internal.tls.SslClient;
|
import okhttp3.internal.tls.SslClient;
|
||||||
import okhttp3.mockwebserver.MockResponse;
|
import okhttp3.mockwebserver.MockResponse;
|
||||||
import okhttp3.mockwebserver.MockWebServer;
|
import okhttp3.mockwebserver.MockWebServer;
|
||||||
|
@@ -62,7 +62,7 @@ import okhttp3.OkHttpClient;
|
|||||||
import okhttp3.OkUrlFactory;
|
import okhttp3.OkUrlFactory;
|
||||||
import okhttp3.RecordingHostnameVerifier;
|
import okhttp3.RecordingHostnameVerifier;
|
||||||
import okhttp3.internal.Internal;
|
import okhttp3.internal.Internal;
|
||||||
import okhttp3.internal.InternalCache;
|
import okhttp3.internal.cache.InternalCache;
|
||||||
import okhttp3.internal.tls.SslClient;
|
import okhttp3.internal.tls.SslClient;
|
||||||
import okhttp3.mockwebserver.MockResponse;
|
import okhttp3.mockwebserver.MockResponse;
|
||||||
import okhttp3.mockwebserver.MockWebServer;
|
import okhttp3.mockwebserver.MockWebServer;
|
||||||
|
@@ -30,12 +30,12 @@ import okhttp3.Request;
|
|||||||
import okhttp3.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
import okhttp3.internal.Platform;
|
import okhttp3.internal.http.HttpHeaders;
|
||||||
import okhttp3.internal.http.OkHeaders;
|
import okhttp3.internal.platform.Platform;
|
||||||
import okio.Buffer;
|
import okio.Buffer;
|
||||||
import okio.BufferedSource;
|
import okio.BufferedSource;
|
||||||
|
|
||||||
import static okhttp3.internal.Platform.INFO;
|
import static okhttp3.internal.platform.Platform.INFO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An OkHttp interceptor which logs request and response information. Can be applied as an
|
* An OkHttp interceptor which logs request and response information. Can be applied as an
|
||||||
@@ -229,7 +229,7 @@ public final class HttpLoggingInterceptor implements Interceptor {
|
|||||||
logger.log(headers.name(i) + ": " + headers.value(i));
|
logger.log(headers.name(i) + ": " + headers.value(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!logBody || !OkHeaders.hasBody(response)) {
|
if (!logBody || !HttpHeaders.hasBody(response)) {
|
||||||
logger.log("<-- END HTTP");
|
logger.log("<-- END HTTP");
|
||||||
} else if (bodyEncoded(response.headers())) {
|
} else if (bodyEncoded(response.headers())) {
|
||||||
logger.log("<-- END HTTP (encoded body omitted)");
|
logger.log("<-- END HTTP (encoded body omitted)");
|
||||||
|
@@ -21,8 +21,8 @@ import java.security.cert.X509Certificate;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||||
import okhttp3.internal.tls.HeldCertificate;
|
|
||||||
import okhttp3.internal.tls.CertificateChainCleaner;
|
import okhttp3.internal.tls.CertificateChainCleaner;
|
||||||
|
import okhttp3.internal.tls.HeldCertificate;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@@ -24,8 +24,8 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import javax.net.SocketFactory;
|
import javax.net.SocketFactory;
|
||||||
import okhttp3.internal.Internal;
|
import okhttp3.internal.Internal;
|
||||||
import okhttp3.internal.RecordingOkAuthenticator;
|
import okhttp3.internal.RecordingOkAuthenticator;
|
||||||
import okhttp3.internal.http.StreamAllocation;
|
import okhttp3.internal.connection.RealConnection;
|
||||||
import okhttp3.internal.io.RealConnection;
|
import okhttp3.internal.connection.StreamAllocation;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package okhttp3.internal.http;
|
package okhttp3;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.CookieHandler;
|
import java.net.CookieHandler;
|
||||||
@@ -27,12 +27,6 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import okhttp3.Call;
|
|
||||||
import okhttp3.HttpUrl;
|
|
||||||
import okhttp3.JavaNetCookieJar;
|
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
import okhttp3.Request;
|
|
||||||
import okhttp3.Response;
|
|
||||||
import okhttp3.mockwebserver.MockResponse;
|
import okhttp3.mockwebserver.MockResponse;
|
||||||
import okhttp3.mockwebserver.MockWebServer;
|
import okhttp3.mockwebserver.MockWebServer;
|
||||||
import okhttp3.mockwebserver.RecordedRequest;
|
import okhttp3.mockwebserver.RecordedRequest;
|
@@ -18,7 +18,6 @@ package okhttp3;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import javax.net.ssl.SSLSocket;
|
import javax.net.ssl.SSLSocket;
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
|
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package okhttp3;
|
package okhttp3;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InterruptedIOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal.http;
|
package okhttp3;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -21,11 +21,8 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import okhttp3.Headers;
|
|
||||||
import okhttp3.Protocol;
|
|
||||||
import okhttp3.Request;
|
|
||||||
import okhttp3.Response;
|
|
||||||
import okhttp3.internal.framed.Header;
|
import okhttp3.internal.framed.Header;
|
||||||
|
import okhttp3.internal.http.Http2xStream;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal;
|
package okhttp3.internal.cache;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -25,6 +25,7 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
import okhttp3.internal.io.FaultyFileSystem;
|
||||||
import okhttp3.internal.io.FileSystem;
|
import okhttp3.internal.io.FileSystem;
|
||||||
import okio.BufferedSink;
|
import okio.BufferedSink;
|
||||||
import okio.BufferedSource;
|
import okio.BufferedSource;
|
||||||
@@ -37,10 +38,10 @@ import org.junit.Test;
|
|||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
import org.junit.rules.Timeout;
|
import org.junit.rules.Timeout;
|
||||||
|
|
||||||
import static okhttp3.internal.DiskLruCache.JOURNAL_FILE;
|
import static okhttp3.internal.cache.DiskLruCache.JOURNAL_FILE;
|
||||||
import static okhttp3.internal.DiskLruCache.JOURNAL_FILE_BACKUP;
|
import static okhttp3.internal.cache.DiskLruCache.JOURNAL_FILE_BACKUP;
|
||||||
import static okhttp3.internal.DiskLruCache.MAGIC;
|
import static okhttp3.internal.cache.DiskLruCache.MAGIC;
|
||||||
import static okhttp3.internal.DiskLruCache.VERSION_1;
|
import static okhttp3.internal.cache.DiskLruCache.VERSION_1;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal;
|
package okhttp3.internal.connection;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
@@ -24,6 +24,7 @@ import javax.net.ssl.SSLHandshakeException;
|
|||||||
import javax.net.ssl.SSLSocket;
|
import javax.net.ssl.SSLSocket;
|
||||||
import okhttp3.ConnectionSpec;
|
import okhttp3.ConnectionSpec;
|
||||||
import okhttp3.TlsVersion;
|
import okhttp3.TlsVersion;
|
||||||
|
import okhttp3.internal.Internal;
|
||||||
import okhttp3.internal.tls.SslClient;
|
import okhttp3.internal.tls.SslClient;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal.http;
|
package okhttp3.internal.connection;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal.http;
|
package okhttp3.internal.connection;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
@@ -37,8 +37,8 @@ import okhttp3.ConnectionSpec;
|
|||||||
import okhttp3.FakeDns;
|
import okhttp3.FakeDns;
|
||||||
import okhttp3.Protocol;
|
import okhttp3.Protocol;
|
||||||
import okhttp3.Route;
|
import okhttp3.Route;
|
||||||
import okhttp3.internal.RouteDatabase;
|
|
||||||
import okhttp3.internal.Util;
|
import okhttp3.internal.Util;
|
||||||
|
import okhttp3.internal.http.RecordingProxySelector;
|
||||||
import okhttp3.internal.tls.SslClient;
|
import okhttp3.internal.tls.SslClient;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
@@ -13,14 +13,13 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal;
|
package okhttp3.internal.io;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import okhttp3.internal.io.FileSystem;
|
|
||||||
import okio.Buffer;
|
import okio.Buffer;
|
||||||
import okio.ForwardingSink;
|
import okio.ForwardingSink;
|
||||||
import okio.Sink;
|
import okio.Sink;
|
@@ -13,11 +13,11 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal;
|
package okhttp3.internal.platform;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static okhttp3.internal.PlatformTest.getPlatform;
|
import static okhttp3.internal.platform.PlatformTest.getPlatform;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assume.assumeTrue;
|
import static org.junit.Assume.assumeTrue;
|
@@ -13,11 +13,11 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal;
|
package okhttp3.internal.platform;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static okhttp3.internal.PlatformTest.getPlatform;
|
import static okhttp3.internal.platform.PlatformTest.getPlatform;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assume.assumeTrue;
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
@@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package okhttp3.internal;
|
package okhttp3.internal.platform;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
@@ -13,13 +13,12 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal;
|
package okhttp3.internal.platform;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class PlatformTest {
|
public class PlatformTest {
|
||||||
@Test
|
@Test public void alwaysBuilds() {
|
||||||
public void alwaysBuilds() {
|
|
||||||
new Platform();
|
new Platform();
|
||||||
}
|
}
|
||||||
|
|
@@ -22,11 +22,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import okhttp3.internal.Platform;
|
import okhttp3.internal.platform.Platform;
|
||||||
|
|
||||||
import static okhttp3.internal.Platform.WARN;
|
|
||||||
import static okhttp3.internal.Util.delimiterOffset;
|
import static okhttp3.internal.Util.delimiterOffset;
|
||||||
import static okhttp3.internal.Util.trimSubstring;
|
import static okhttp3.internal.Util.trimSubstring;
|
||||||
|
import static okhttp3.internal.platform.Platform.WARN;
|
||||||
|
|
||||||
/** A cookie jar that delegates to a {@link java.net.CookieHandler}. */
|
/** A cookie jar that delegates to a {@link java.net.CookieHandler}. */
|
||||||
public final class JavaNetCookieJar implements CookieJar {
|
public final class JavaNetCookieJar implements CookieJar {
|
||||||
|
@@ -49,16 +49,16 @@ import okhttp3.Request;
|
|||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.internal.Internal;
|
import okhttp3.internal.Internal;
|
||||||
import okhttp3.internal.JavaNetHeaders;
|
import okhttp3.internal.JavaNetHeaders;
|
||||||
import okhttp3.internal.Platform;
|
|
||||||
import okhttp3.internal.URLFilter;
|
import okhttp3.internal.URLFilter;
|
||||||
import okhttp3.internal.Util;
|
import okhttp3.internal.Util;
|
||||||
import okhttp3.internal.Version;
|
import okhttp3.internal.Version;
|
||||||
import okhttp3.internal.http.HttpDate;
|
import okhttp3.internal.http.HttpDate;
|
||||||
|
import okhttp3.internal.http.HttpHeaders;
|
||||||
import okhttp3.internal.http.HttpMethod;
|
import okhttp3.internal.http.HttpMethod;
|
||||||
import okhttp3.internal.http.OkHeaders;
|
|
||||||
import okhttp3.internal.http.StatusLine;
|
import okhttp3.internal.http.StatusLine;
|
||||||
|
import okhttp3.internal.platform.Platform;
|
||||||
|
|
||||||
import static okhttp3.internal.Platform.WARN;
|
import static okhttp3.internal.platform.Platform.WARN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This implementation uses {@linkplain Call} to send requests and receive responses.
|
* This implementation uses {@linkplain Call} to send requests and receive responses.
|
||||||
@@ -152,7 +152,7 @@ public final class OkHttpURLConnection extends HttpURLConnection implements Call
|
|||||||
@Override public InputStream getErrorStream() {
|
@Override public InputStream getErrorStream() {
|
||||||
try {
|
try {
|
||||||
Response response = getResponse();
|
Response response = getResponse();
|
||||||
if (OkHeaders.hasBody(response) && response.code() >= HTTP_BAD_REQUEST) {
|
if (HttpHeaders.hasBody(response) && response.code() >= HTTP_BAD_REQUEST) {
|
||||||
return response.body().byteStream();
|
return response.body().byteStream();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@@ -27,9 +27,9 @@ import okhttp3.OkUrlFactory;
|
|||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.internal.Internal;
|
import okhttp3.internal.Internal;
|
||||||
import okhttp3.internal.InternalCache;
|
import okhttp3.internal.cache.CacheRequest;
|
||||||
import okhttp3.internal.http.CacheRequest;
|
import okhttp3.internal.cache.CacheStrategy;
|
||||||
import okhttp3.internal.http.CacheStrategy;
|
import okhttp3.internal.cache.InternalCache;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@@ -31,7 +31,7 @@ import okhttp3.Request;
|
|||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.internal.Internal;
|
import okhttp3.internal.Internal;
|
||||||
import okhttp3.internal.Util;
|
import okhttp3.internal.Util;
|
||||||
import okhttp3.internal.http.StreamAllocation;
|
import okhttp3.internal.connection.StreamAllocation;
|
||||||
import okhttp3.internal.ws.RealWebSocket;
|
import okhttp3.internal.ws.RealWebSocket;
|
||||||
import okhttp3.internal.ws.WebSocketProtocol;
|
import okhttp3.internal.ws.WebSocketProtocol;
|
||||||
import okio.ByteString;
|
import okio.ByteString;
|
||||||
|
@@ -28,16 +28,16 @@ import java.util.Collections;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import okhttp3.internal.DiskLruCache;
|
|
||||||
import okhttp3.internal.InternalCache;
|
|
||||||
import okhttp3.internal.Platform;
|
|
||||||
import okhttp3.internal.Util;
|
import okhttp3.internal.Util;
|
||||||
import okhttp3.internal.http.CacheRequest;
|
import okhttp3.internal.cache.CacheRequest;
|
||||||
import okhttp3.internal.http.CacheStrategy;
|
import okhttp3.internal.cache.CacheStrategy;
|
||||||
|
import okhttp3.internal.cache.DiskLruCache;
|
||||||
|
import okhttp3.internal.cache.InternalCache;
|
||||||
|
import okhttp3.internal.http.HttpHeaders;
|
||||||
import okhttp3.internal.http.HttpMethod;
|
import okhttp3.internal.http.HttpMethod;
|
||||||
import okhttp3.internal.http.OkHeaders;
|
|
||||||
import okhttp3.internal.http.StatusLine;
|
import okhttp3.internal.http.StatusLine;
|
||||||
import okhttp3.internal.io.FileSystem;
|
import okhttp3.internal.io.FileSystem;
|
||||||
|
import okhttp3.internal.platform.Platform;
|
||||||
import okio.Buffer;
|
import okio.Buffer;
|
||||||
import okio.BufferedSink;
|
import okio.BufferedSink;
|
||||||
import okio.BufferedSource;
|
import okio.BufferedSource;
|
||||||
@@ -235,7 +235,7 @@ public final class Cache implements Closeable, Flushable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OkHeaders.hasVaryAll(response)) {
|
if (HttpHeaders.hasVaryAll(response)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -592,7 +592,7 @@ public final class Cache implements Closeable, Flushable {
|
|||||||
|
|
||||||
public Entry(Response response) {
|
public Entry(Response response) {
|
||||||
this.url = response.request().url().toString();
|
this.url = response.request().url().toString();
|
||||||
this.varyHeaders = OkHeaders.varyHeaders(response);
|
this.varyHeaders = HttpHeaders.varyHeaders(response);
|
||||||
this.requestMethod = response.request().method();
|
this.requestMethod = response.request().method();
|
||||||
this.protocol = response.protocol();
|
this.protocol = response.protocol();
|
||||||
this.code = response.code();
|
this.code = response.code();
|
||||||
@@ -695,7 +695,7 @@ public final class Cache implements Closeable, Flushable {
|
|||||||
public boolean matches(Request request, Response response) {
|
public boolean matches(Request request, Response response) {
|
||||||
return url.equals(request.url().toString())
|
return url.equals(request.url().toString())
|
||||||
&& requestMethod.equals(request.method())
|
&& requestMethod.equals(request.method())
|
||||||
&& OkHeaders.varyMatches(response, varyHeaders, request);
|
&& HttpHeaders.varyMatches(response, varyHeaders, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response response(DiskLruCache.Snapshot snapshot) {
|
public Response response(DiskLruCache.Snapshot snapshot) {
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package okhttp3;
|
package okhttp3;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import okhttp3.internal.http.HeaderParser;
|
import okhttp3.internal.http.HttpHeaders;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Cache-Control header with cache directives from a server or client. These directives set policy
|
* A Cache-Control header with cache directives from a server or client. These directives set policy
|
||||||
@@ -178,7 +178,7 @@ public final class CacheControl {
|
|||||||
int pos = 0;
|
int pos = 0;
|
||||||
while (pos < value.length()) {
|
while (pos < value.length()) {
|
||||||
int tokenStart = pos;
|
int tokenStart = pos;
|
||||||
pos = HeaderParser.skipUntil(value, pos, "=,;");
|
pos = HttpHeaders.skipUntil(value, pos, "=,;");
|
||||||
String directive = value.substring(tokenStart, pos).trim();
|
String directive = value.substring(tokenStart, pos).trim();
|
||||||
String parameter;
|
String parameter;
|
||||||
|
|
||||||
@@ -187,20 +187,20 @@ public final class CacheControl {
|
|||||||
parameter = null;
|
parameter = null;
|
||||||
} else {
|
} else {
|
||||||
pos++; // consume '='
|
pos++; // consume '='
|
||||||
pos = HeaderParser.skipWhitespace(value, pos);
|
pos = HttpHeaders.skipWhitespace(value, pos);
|
||||||
|
|
||||||
// quoted string
|
// quoted string
|
||||||
if (pos < value.length() && value.charAt(pos) == '\"') {
|
if (pos < value.length() && value.charAt(pos) == '\"') {
|
||||||
pos++; // consume '"' open quote
|
pos++; // consume '"' open quote
|
||||||
int parameterStart = pos;
|
int parameterStart = pos;
|
||||||
pos = HeaderParser.skipUntil(value, pos, "\"");
|
pos = HttpHeaders.skipUntil(value, pos, "\"");
|
||||||
parameter = value.substring(parameterStart, pos);
|
parameter = value.substring(parameterStart, pos);
|
||||||
pos++; // consume '"' close quote (if necessary)
|
pos++; // consume '"' close quote (if necessary)
|
||||||
|
|
||||||
// unquoted string
|
// unquoted string
|
||||||
} else {
|
} else {
|
||||||
int parameterStart = pos;
|
int parameterStart = pos;
|
||||||
pos = HeaderParser.skipUntil(value, pos, ",;");
|
pos = HttpHeaders.skipUntil(value, pos, ",;");
|
||||||
parameter = value.substring(parameterStart, pos).trim();
|
parameter = value.substring(parameterStart, pos).trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,9 +210,9 @@ public final class CacheControl {
|
|||||||
} else if ("no-store".equalsIgnoreCase(directive)) {
|
} else if ("no-store".equalsIgnoreCase(directive)) {
|
||||||
noStore = true;
|
noStore = true;
|
||||||
} else if ("max-age".equalsIgnoreCase(directive)) {
|
} else if ("max-age".equalsIgnoreCase(directive)) {
|
||||||
maxAgeSeconds = HeaderParser.parseSeconds(parameter, -1);
|
maxAgeSeconds = HttpHeaders.parseSeconds(parameter, -1);
|
||||||
} else if ("s-maxage".equalsIgnoreCase(directive)) {
|
} else if ("s-maxage".equalsIgnoreCase(directive)) {
|
||||||
sMaxAgeSeconds = HeaderParser.parseSeconds(parameter, -1);
|
sMaxAgeSeconds = HttpHeaders.parseSeconds(parameter, -1);
|
||||||
} else if ("private".equalsIgnoreCase(directive)) {
|
} else if ("private".equalsIgnoreCase(directive)) {
|
||||||
isPrivate = true;
|
isPrivate = true;
|
||||||
} else if ("public".equalsIgnoreCase(directive)) {
|
} else if ("public".equalsIgnoreCase(directive)) {
|
||||||
@@ -220,9 +220,9 @@ public final class CacheControl {
|
|||||||
} else if ("must-revalidate".equalsIgnoreCase(directive)) {
|
} else if ("must-revalidate".equalsIgnoreCase(directive)) {
|
||||||
mustRevalidate = true;
|
mustRevalidate = true;
|
||||||
} else if ("max-stale".equalsIgnoreCase(directive)) {
|
} else if ("max-stale".equalsIgnoreCase(directive)) {
|
||||||
maxStaleSeconds = HeaderParser.parseSeconds(parameter, Integer.MAX_VALUE);
|
maxStaleSeconds = HttpHeaders.parseSeconds(parameter, Integer.MAX_VALUE);
|
||||||
} else if ("min-fresh".equalsIgnoreCase(directive)) {
|
} else if ("min-fresh".equalsIgnoreCase(directive)) {
|
||||||
minFreshSeconds = HeaderParser.parseSeconds(parameter, -1);
|
minFreshSeconds = HttpHeaders.parseSeconds(parameter, -1);
|
||||||
} else if ("only-if-cached".equalsIgnoreCase(directive)) {
|
} else if ("only-if-cached".equalsIgnoreCase(directive)) {
|
||||||
onlyIfCached = true;
|
onlyIfCached = true;
|
||||||
} else if ("no-transform".equalsIgnoreCase(directive)) {
|
} else if ("no-transform".equalsIgnoreCase(directive)) {
|
||||||
|
@@ -26,14 +26,14 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.concurrent.SynchronousQueue;
|
import java.util.concurrent.SynchronousQueue;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import okhttp3.internal.Platform;
|
|
||||||
import okhttp3.internal.RouteDatabase;
|
|
||||||
import okhttp3.internal.Util;
|
import okhttp3.internal.Util;
|
||||||
import okhttp3.internal.http.StreamAllocation;
|
import okhttp3.internal.connection.RealConnection;
|
||||||
import okhttp3.internal.io.RealConnection;
|
import okhttp3.internal.connection.RouteDatabase;
|
||||||
|
import okhttp3.internal.connection.StreamAllocation;
|
||||||
|
import okhttp3.internal.platform.Platform;
|
||||||
|
|
||||||
import static okhttp3.internal.Platform.WARN;
|
|
||||||
import static okhttp3.internal.Util.closeQuietly;
|
import static okhttp3.internal.Util.closeQuietly;
|
||||||
|
import static okhttp3.internal.platform.Platform.WARN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages reuse of HTTP and SPDY connections for reduced network latency. HTTP requests that share
|
* Manages reuse of HTTP and SPDY connections for reduced network latency. HTTP requests that share
|
||||||
|
@@ -34,12 +34,12 @@ import javax.net.ssl.TrustManager;
|
|||||||
import javax.net.ssl.TrustManagerFactory;
|
import javax.net.ssl.TrustManagerFactory;
|
||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
import okhttp3.internal.Internal;
|
import okhttp3.internal.Internal;
|
||||||
import okhttp3.internal.InternalCache;
|
|
||||||
import okhttp3.internal.Platform;
|
|
||||||
import okhttp3.internal.RouteDatabase;
|
|
||||||
import okhttp3.internal.Util;
|
import okhttp3.internal.Util;
|
||||||
import okhttp3.internal.http.StreamAllocation;
|
import okhttp3.internal.cache.InternalCache;
|
||||||
import okhttp3.internal.io.RealConnection;
|
import okhttp3.internal.connection.RealConnection;
|
||||||
|
import okhttp3.internal.connection.RouteDatabase;
|
||||||
|
import okhttp3.internal.connection.StreamAllocation;
|
||||||
|
import okhttp3.internal.platform.Platform;
|
||||||
import okhttp3.internal.tls.CertificateChainCleaner;
|
import okhttp3.internal.tls.CertificateChainCleaner;
|
||||||
import okhttp3.internal.tls.OkHostnameVerifier;
|
import okhttp3.internal.tls.OkHostnameVerifier;
|
||||||
|
|
||||||
|
@@ -19,16 +19,16 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import okhttp3.internal.NamedRunnable;
|
import okhttp3.internal.NamedRunnable;
|
||||||
import okhttp3.internal.Platform;
|
import okhttp3.internal.cache.CacheInterceptor;
|
||||||
|
import okhttp3.internal.connection.ConnectInterceptor;
|
||||||
|
import okhttp3.internal.connection.StreamAllocation;
|
||||||
import okhttp3.internal.http.BridgeInterceptor;
|
import okhttp3.internal.http.BridgeInterceptor;
|
||||||
import okhttp3.internal.http.CacheInterceptor;
|
|
||||||
import okhttp3.internal.http.CallServerInterceptor;
|
import okhttp3.internal.http.CallServerInterceptor;
|
||||||
import okhttp3.internal.http.ConnectInterceptor;
|
|
||||||
import okhttp3.internal.http.RealInterceptorChain;
|
import okhttp3.internal.http.RealInterceptorChain;
|
||||||
import okhttp3.internal.http.RetryAndFollowUpInterceptor;
|
import okhttp3.internal.http.RetryAndFollowUpInterceptor;
|
||||||
import okhttp3.internal.http.StreamAllocation;
|
import okhttp3.internal.platform.Platform;
|
||||||
|
|
||||||
import static okhttp3.internal.Platform.INFO;
|
import static okhttp3.internal.platform.Platform.INFO;
|
||||||
|
|
||||||
final class RealCall implements Call {
|
final class RealCall implements Call {
|
||||||
private final OkHttpClient client;
|
private final OkHttpClient client;
|
||||||
|
@@ -19,7 +19,7 @@ import java.io.Closeable;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import okhttp3.internal.http.OkHeaders;
|
import okhttp3.internal.http.HttpHeaders;
|
||||||
import okio.Buffer;
|
import okio.Buffer;
|
||||||
import okio.BufferedSource;
|
import okio.BufferedSource;
|
||||||
|
|
||||||
@@ -234,7 +234,7 @@ public final class Response implements Closeable {
|
|||||||
} else {
|
} else {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
return OkHeaders.parseChallenges(headers(), responseField);
|
return HttpHeaders.parseChallenges(headers(), responseField);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -25,8 +25,10 @@ import okhttp3.ConnectionSpec;
|
|||||||
import okhttp3.Headers;
|
import okhttp3.Headers;
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.internal.http.StreamAllocation;
|
import okhttp3.internal.cache.InternalCache;
|
||||||
import okhttp3.internal.io.RealConnection;
|
import okhttp3.internal.connection.RealConnection;
|
||||||
|
import okhttp3.internal.connection.RouteDatabase;
|
||||||
|
import okhttp3.internal.connection.StreamAllocation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Escalate internal APIs in {@code okhttp3} so they can be used from OkHttp's implementation
|
* Escalate internal APIs in {@code okhttp3} so they can be used from OkHttp's implementation
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal.http;
|
package okhttp3.internal.cache;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -26,7 +26,10 @@ import okhttp3.Request;
|
|||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
import okhttp3.internal.Internal;
|
import okhttp3.internal.Internal;
|
||||||
import okhttp3.internal.InternalCache;
|
import okhttp3.internal.http.HttpHeaders;
|
||||||
|
import okhttp3.internal.http.HttpMethod;
|
||||||
|
import okhttp3.internal.http.HttpStream;
|
||||||
|
import okhttp3.internal.http.RealResponseBody;
|
||||||
import okio.Buffer;
|
import okio.Buffer;
|
||||||
import okio.BufferedSink;
|
import okio.BufferedSink;
|
||||||
import okio.BufferedSource;
|
import okio.BufferedSource;
|
||||||
@@ -136,7 +139,7 @@ public final class CacheInterceptor implements Interceptor {
|
|||||||
.networkResponse(stripBody(networkResponse))
|
.networkResponse(stripBody(networkResponse))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
if (OkHeaders.hasBody(response)) {
|
if (HttpHeaders.hasBody(response)) {
|
||||||
CacheRequest cacheRequest = maybeCache(response, networkResponse.request(), cache);
|
CacheRequest cacheRequest = maybeCache(response, networkResponse.request(), cache);
|
||||||
response = cacheWritingResponse(cacheRequest, response);
|
response = cacheWritingResponse(cacheRequest, response);
|
||||||
}
|
}
|
||||||
@@ -264,7 +267,7 @@ public final class CacheInterceptor implements Interceptor {
|
|||||||
if ("Warning".equalsIgnoreCase(fieldName) && value.startsWith("1")) {
|
if ("Warning".equalsIgnoreCase(fieldName) && value.startsWith("1")) {
|
||||||
continue; // Drop 100-level freshness warnings.
|
continue; // Drop 100-level freshness warnings.
|
||||||
}
|
}
|
||||||
if (!OkHeaders.isEndToEnd(fieldName) || networkHeaders.get(fieldName) == null) {
|
if (!isEndToEnd(fieldName) || networkHeaders.get(fieldName) == null) {
|
||||||
Internal.instance.addLenient(result, fieldName, value);
|
Internal.instance.addLenient(result, fieldName, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -274,11 +277,26 @@ public final class CacheInterceptor implements Interceptor {
|
|||||||
if ("Content-Length".equalsIgnoreCase(fieldName)) {
|
if ("Content-Length".equalsIgnoreCase(fieldName)) {
|
||||||
continue; // Ignore content-length headers of validating responses.
|
continue; // Ignore content-length headers of validating responses.
|
||||||
}
|
}
|
||||||
if (OkHeaders.isEndToEnd(fieldName)) {
|
if (isEndToEnd(fieldName)) {
|
||||||
Internal.instance.addLenient(result, fieldName, networkHeaders.value(i));
|
Internal.instance.addLenient(result, fieldName, networkHeaders.value(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.build();
|
return result.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if {@code fieldName} is an end-to-end HTTP header, as defined by RFC 2616,
|
||||||
|
* 13.5.1.
|
||||||
|
*/
|
||||||
|
static boolean isEndToEnd(String fieldName) {
|
||||||
|
return !"Connection".equalsIgnoreCase(fieldName)
|
||||||
|
&& !"Keep-Alive".equalsIgnoreCase(fieldName)
|
||||||
|
&& !"Proxy-Authenticate".equalsIgnoreCase(fieldName)
|
||||||
|
&& !"Proxy-Authorization".equalsIgnoreCase(fieldName)
|
||||||
|
&& !"TE".equalsIgnoreCase(fieldName)
|
||||||
|
&& !"Trailers".equalsIgnoreCase(fieldName)
|
||||||
|
&& !"Transfer-Encoding".equalsIgnoreCase(fieldName)
|
||||||
|
&& !"Upgrade".equalsIgnoreCase(fieldName);
|
||||||
|
}
|
||||||
}
|
}
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal.http;
|
package okhttp3.internal.cache;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import okio.Sink;
|
import okio.Sink;
|
@@ -13,13 +13,16 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal.http;
|
package okhttp3.internal.cache;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import okhttp3.CacheControl;
|
import okhttp3.CacheControl;
|
||||||
import okhttp3.Headers;
|
import okhttp3.Headers;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
import okhttp3.internal.http.HttpDate;
|
||||||
|
import okhttp3.internal.http.HttpHeaders;
|
||||||
|
import okhttp3.internal.http.StatusLine;
|
||||||
|
|
||||||
import static java.net.HttpURLConnection.HTTP_BAD_METHOD;
|
import static java.net.HttpURLConnection.HTTP_BAD_METHOD;
|
||||||
import static java.net.HttpURLConnection.HTTP_GONE;
|
import static java.net.HttpURLConnection.HTTP_GONE;
|
||||||
@@ -155,7 +158,7 @@ public final class CacheStrategy {
|
|||||||
} else if ("ETag".equalsIgnoreCase(fieldName)) {
|
} else if ("ETag".equalsIgnoreCase(fieldName)) {
|
||||||
etag = value;
|
etag = value;
|
||||||
} else if ("Age".equalsIgnoreCase(fieldName)) {
|
} else if ("Age".equalsIgnoreCase(fieldName)) {
|
||||||
ageSeconds = HeaderParser.parseSeconds(value, -1);
|
ageSeconds = HttpHeaders.parseSeconds(value, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal;
|
package okhttp3.internal.cache;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
@@ -32,7 +32,9 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import okhttp3.internal.Util;
|
||||||
import okhttp3.internal.io.FileSystem;
|
import okhttp3.internal.io.FileSystem;
|
||||||
|
import okhttp3.internal.platform.Platform;
|
||||||
import okio.Buffer;
|
import okio.Buffer;
|
||||||
import okio.BufferedSink;
|
import okio.BufferedSink;
|
||||||
import okio.BufferedSource;
|
import okio.BufferedSource;
|
||||||
@@ -41,7 +43,7 @@ import okio.Sink;
|
|||||||
import okio.Source;
|
import okio.Source;
|
||||||
import okio.Timeout;
|
import okio.Timeout;
|
||||||
|
|
||||||
import static okhttp3.internal.Platform.WARN;
|
import static okhttp3.internal.platform.Platform.WARN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A cache that uses a bounded amount of space on a filesystem. Each cache entry has a string key
|
* A cache that uses a bounded amount of space on a filesystem. Each cache entry has a string key
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal;
|
package okhttp3.internal.cache;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import okio.Buffer;
|
import okio.Buffer;
|
@@ -13,13 +13,11 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal;
|
package okhttp3.internal.cache;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.internal.http.CacheRequest;
|
|
||||||
import okhttp3.internal.http.CacheStrategy;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OkHttp's internal cache interface. Applications shouldn't implement this: instead use {@link
|
* OkHttp's internal cache interface. Applications shouldn't implement this: instead use {@link
|
@@ -14,14 +14,15 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal.http;
|
package okhttp3.internal.connection;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import okhttp3.Interceptor;
|
import okhttp3.Interceptor;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.internal.io.RealConnection;
|
import okhttp3.internal.http.HttpStream;
|
||||||
|
import okhttp3.internal.http.RealInterceptorChain;
|
||||||
|
|
||||||
/** Opens a connection to the target server and proceeds to the next interceptor. */
|
/** Opens a connection to the target server and proceeds to the next interceptor. */
|
||||||
public final class ConnectInterceptor implements Interceptor {
|
public final class ConnectInterceptor implements Interceptor {
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal;
|
package okhttp3.internal.connection;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InterruptedIOException;
|
import java.io.InterruptedIOException;
|
||||||
@@ -27,6 +27,7 @@ import javax.net.ssl.SSLPeerUnverifiedException;
|
|||||||
import javax.net.ssl.SSLProtocolException;
|
import javax.net.ssl.SSLProtocolException;
|
||||||
import javax.net.ssl.SSLSocket;
|
import javax.net.ssl.SSLSocket;
|
||||||
import okhttp3.ConnectionSpec;
|
import okhttp3.ConnectionSpec;
|
||||||
|
import okhttp3.internal.Internal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the connection spec fallback strategy: When a secure socket connection fails due to a
|
* Handles the connection spec fallback strategy: When a secure socket connection fails due to a
|
@@ -14,7 +14,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal.io;
|
package okhttp3.internal.connection;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ref.Reference;
|
import java.lang.ref.Reference;
|
||||||
@@ -41,17 +41,14 @@ import okhttp3.Protocol;
|
|||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.Route;
|
import okhttp3.Route;
|
||||||
import okhttp3.internal.ConnectionSpecSelector;
|
|
||||||
import okhttp3.internal.Platform;
|
|
||||||
import okhttp3.internal.Util;
|
import okhttp3.internal.Util;
|
||||||
import okhttp3.internal.Version;
|
import okhttp3.internal.Version;
|
||||||
import okhttp3.internal.framed.ErrorCode;
|
import okhttp3.internal.framed.ErrorCode;
|
||||||
import okhttp3.internal.framed.FramedConnection;
|
import okhttp3.internal.framed.FramedConnection;
|
||||||
import okhttp3.internal.framed.FramedStream;
|
import okhttp3.internal.framed.FramedStream;
|
||||||
import okhttp3.internal.http.Http1xStream;
|
import okhttp3.internal.http.Http1xStream;
|
||||||
import okhttp3.internal.http.OkHeaders;
|
import okhttp3.internal.http.HttpHeaders;
|
||||||
import okhttp3.internal.http.RouteException;
|
import okhttp3.internal.platform.Platform;
|
||||||
import okhttp3.internal.http.StreamAllocation;
|
|
||||||
import okhttp3.internal.tls.OkHostnameVerifier;
|
import okhttp3.internal.tls.OkHostnameVerifier;
|
||||||
import okio.BufferedSink;
|
import okio.BufferedSink;
|
||||||
import okio.BufferedSource;
|
import okio.BufferedSource;
|
||||||
@@ -294,7 +291,7 @@ public final class RealConnection extends FramedConnection.Listener implements C
|
|||||||
Response response = tunnelConnection.readResponse().request(tunnelRequest).build();
|
Response response = tunnelConnection.readResponse().request(tunnelRequest).build();
|
||||||
// The response body from a CONNECT should be empty, but if it is not then we should consume
|
// The response body from a CONNECT should be empty, but if it is not then we should consume
|
||||||
// it before proceeding.
|
// it before proceeding.
|
||||||
long contentLength = OkHeaders.contentLength(response);
|
long contentLength = HttpHeaders.contentLength(response);
|
||||||
if (contentLength == -1L) {
|
if (contentLength == -1L) {
|
||||||
contentLength = 0L;
|
contentLength = 0L;
|
||||||
}
|
}
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal;
|
package okhttp3.internal.connection;
|
||||||
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal.http;
|
package okhttp3.internal.connection;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal.http;
|
package okhttp3.internal.connection;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
@@ -28,7 +28,6 @@ import java.util.NoSuchElementException;
|
|||||||
import okhttp3.Address;
|
import okhttp3.Address;
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
import okhttp3.Route;
|
import okhttp3.Route;
|
||||||
import okhttp3.internal.RouteDatabase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selects routes to connect to an origin server. Each connection requires a choice of proxy server,
|
* Selects routes to connect to an origin server. Each connection requires a choice of proxy server,
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal.http;
|
package okhttp3.internal.connection;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ref.Reference;
|
import java.lang.ref.Reference;
|
||||||
@@ -23,11 +23,12 @@ import okhttp3.ConnectionPool;
|
|||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Route;
|
import okhttp3.Route;
|
||||||
import okhttp3.internal.Internal;
|
import okhttp3.internal.Internal;
|
||||||
import okhttp3.internal.RouteDatabase;
|
|
||||||
import okhttp3.internal.Util;
|
import okhttp3.internal.Util;
|
||||||
import okhttp3.internal.framed.ErrorCode;
|
import okhttp3.internal.framed.ErrorCode;
|
||||||
import okhttp3.internal.framed.StreamResetException;
|
import okhttp3.internal.framed.StreamResetException;
|
||||||
import okhttp3.internal.io.RealConnection;
|
import okhttp3.internal.http.Http1xStream;
|
||||||
|
import okhttp3.internal.http.Http2xStream;
|
||||||
|
import okhttp3.internal.http.HttpStream;
|
||||||
|
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
|
@@ -32,16 +32,16 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import okhttp3.Protocol;
|
import okhttp3.Protocol;
|
||||||
import okhttp3.internal.NamedRunnable;
|
import okhttp3.internal.NamedRunnable;
|
||||||
import okhttp3.internal.Platform;
|
|
||||||
import okhttp3.internal.Util;
|
import okhttp3.internal.Util;
|
||||||
|
import okhttp3.internal.platform.Platform;
|
||||||
import okio.Buffer;
|
import okio.Buffer;
|
||||||
import okio.BufferedSink;
|
import okio.BufferedSink;
|
||||||
import okio.BufferedSource;
|
import okio.BufferedSource;
|
||||||
import okio.ByteString;
|
import okio.ByteString;
|
||||||
import okio.Okio;
|
import okio.Okio;
|
||||||
|
|
||||||
import static okhttp3.internal.Platform.INFO;
|
|
||||||
import static okhttp3.internal.framed.Settings.DEFAULT_INITIAL_WINDOW_SIZE;
|
import static okhttp3.internal.framed.Settings.DEFAULT_INITIAL_WINDOW_SIZE;
|
||||||
|
import static okhttp3.internal.platform.Platform.INFO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A socket connection to a remote peer. A connection hosts streams which can send and receive
|
* A socket connection to a remote peer. A connection hosts streams which can send and receive
|
||||||
|
@@ -92,14 +92,14 @@ public final class BridgeInterceptor implements Interceptor {
|
|||||||
|
|
||||||
Response networkResponse = chain.proceed(requestBuilder.build());
|
Response networkResponse = chain.proceed(requestBuilder.build());
|
||||||
|
|
||||||
OkHeaders.receiveHeaders(cookieJar, userRequest.url(), networkResponse.headers());
|
HttpHeaders.receiveHeaders(cookieJar, userRequest.url(), networkResponse.headers());
|
||||||
|
|
||||||
Response.Builder responseBuilder = networkResponse.newBuilder()
|
Response.Builder responseBuilder = networkResponse.newBuilder()
|
||||||
.request(userRequest);
|
.request(userRequest);
|
||||||
|
|
||||||
if (transparentGzip
|
if (transparentGzip
|
||||||
&& "gzip".equalsIgnoreCase(networkResponse.header("Content-Encoding"))
|
&& "gzip".equalsIgnoreCase(networkResponse.header("Content-Encoding"))
|
||||||
&& OkHeaders.hasBody(networkResponse)) {
|
&& HttpHeaders.hasBody(networkResponse)) {
|
||||||
GzipSource responseBody = new GzipSource(networkResponse.body().source());
|
GzipSource responseBody = new GzipSource(networkResponse.body().source());
|
||||||
Headers strippedHeaders = networkResponse.headers().newBuilder()
|
Headers strippedHeaders = networkResponse.headers().newBuilder()
|
||||||
.removeAll("Content-Encoding")
|
.removeAll("Content-Encoding")
|
||||||
|
@@ -20,6 +20,7 @@ import java.net.ProtocolException;
|
|||||||
import okhttp3.Interceptor;
|
import okhttp3.Interceptor;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
import okhttp3.internal.connection.StreamAllocation;
|
||||||
import okio.BufferedSink;
|
import okio.BufferedSink;
|
||||||
import okio.Okio;
|
import okio.Okio;
|
||||||
import okio.Sink;
|
import okio.Sink;
|
||||||
|
@@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package okhttp3.internal.http;
|
|
||||||
|
|
||||||
public final class HeaderParser {
|
|
||||||
/**
|
|
||||||
* Returns the next index in {@code input} at or after {@code pos} that contains a character from
|
|
||||||
* {@code characters}. Returns the input length if none of the requested characters can be found.
|
|
||||||
*/
|
|
||||||
public static int skipUntil(String input, int pos, String characters) {
|
|
||||||
for (; pos < input.length(); pos++) {
|
|
||||||
if (characters.indexOf(input.charAt(pos)) != -1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the next non-whitespace character in {@code input} that is white space. Result is
|
|
||||||
* undefined if input contains newline characters.
|
|
||||||
*/
|
|
||||||
public static int skipWhitespace(String input, int pos) {
|
|
||||||
for (; pos < input.length(); pos++) {
|
|
||||||
char c = input.charAt(pos);
|
|
||||||
if (c != ' ' && c != '\t') {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns {@code value} as a positive integer, or 0 if it is negative, or {@code defaultValue} if
|
|
||||||
* it cannot be parsed.
|
|
||||||
*/
|
|
||||||
public static int parseSeconds(String value, int defaultValue) {
|
|
||||||
try {
|
|
||||||
long seconds = Long.parseLong(value);
|
|
||||||
if (seconds > Integer.MAX_VALUE) {
|
|
||||||
return Integer.MAX_VALUE;
|
|
||||||
} else if (seconds < 0) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return (int) seconds;
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private HeaderParser() {
|
|
||||||
}
|
|
||||||
}
|
|
@@ -26,7 +26,8 @@ import okhttp3.Response;
|
|||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
import okhttp3.internal.Internal;
|
import okhttp3.internal.Internal;
|
||||||
import okhttp3.internal.Util;
|
import okhttp3.internal.Util;
|
||||||
import okhttp3.internal.io.RealConnection;
|
import okhttp3.internal.connection.RealConnection;
|
||||||
|
import okhttp3.internal.connection.StreamAllocation;
|
||||||
import okio.Buffer;
|
import okio.Buffer;
|
||||||
import okio.BufferedSink;
|
import okio.BufferedSink;
|
||||||
import okio.BufferedSource;
|
import okio.BufferedSource;
|
||||||
@@ -132,7 +133,7 @@ public final class Http1xStream implements HttpStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Source getTransferStream(Response response) throws IOException {
|
private Source getTransferStream(Response response) throws IOException {
|
||||||
if (!OkHeaders.hasBody(response)) {
|
if (!HttpHeaders.hasBody(response)) {
|
||||||
return newFixedLengthSource(0);
|
return newFixedLengthSource(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +141,7 @@ public final class Http1xStream implements HttpStream {
|
|||||||
return newChunkedSource(response.request().url());
|
return newChunkedSource(response.request().url());
|
||||||
}
|
}
|
||||||
|
|
||||||
long contentLength = OkHeaders.contentLength(response);
|
long contentLength = HttpHeaders.contentLength(response);
|
||||||
if (contentLength != -1) {
|
if (contentLength != -1) {
|
||||||
return newFixedLengthSource(contentLength);
|
return newFixedLengthSource(contentLength);
|
||||||
}
|
}
|
||||||
@@ -444,7 +445,7 @@ public final class Http1xStream implements HttpStream {
|
|||||||
}
|
}
|
||||||
if (bytesRemainingInChunk == 0L) {
|
if (bytesRemainingInChunk == 0L) {
|
||||||
hasMoreChunks = false;
|
hasMoreChunks = false;
|
||||||
OkHeaders.receiveHeaders(client.cookieJar(), url, readHeaders());
|
HttpHeaders.receiveHeaders(client.cookieJar(), url, readHeaders());
|
||||||
endOfInput(true);
|
endOfInput(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,7 @@ import okhttp3.Response;
|
|||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
import okhttp3.internal.Internal;
|
import okhttp3.internal.Internal;
|
||||||
import okhttp3.internal.Util;
|
import okhttp3.internal.Util;
|
||||||
|
import okhttp3.internal.connection.StreamAllocation;
|
||||||
import okhttp3.internal.framed.ErrorCode;
|
import okhttp3.internal.framed.ErrorCode;
|
||||||
import okhttp3.internal.framed.FramedConnection;
|
import okhttp3.internal.framed.FramedConnection;
|
||||||
import okhttp3.internal.framed.FramedStream;
|
import okhttp3.internal.framed.FramedStream;
|
||||||
|
@@ -34,8 +34,8 @@ import static okhttp3.internal.Util.equal;
|
|||||||
import static okhttp3.internal.http.StatusLine.HTTP_CONTINUE;
|
import static okhttp3.internal.http.StatusLine.HTTP_CONTINUE;
|
||||||
|
|
||||||
/** Headers and utilities for internal use by OkHttp. */
|
/** Headers and utilities for internal use by OkHttp. */
|
||||||
public final class OkHeaders {
|
public final class HttpHeaders {
|
||||||
private OkHeaders() {
|
private HttpHeaders() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long contentLength(Request request) {
|
public static long contentLength(Request request) {
|
||||||
@@ -139,24 +139,7 @@ public final class OkHeaders {
|
|||||||
return result.build();
|
return result.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Parse RFC 2617 challenges. This API is only interested in the scheme name and realm. */
|
||||||
* Returns true if {@code fieldName} is an end-to-end HTTP header, as defined by RFC 2616,
|
|
||||||
* 13.5.1.
|
|
||||||
*/
|
|
||||||
static boolean isEndToEnd(String fieldName) {
|
|
||||||
return !"Connection".equalsIgnoreCase(fieldName)
|
|
||||||
&& !"Keep-Alive".equalsIgnoreCase(fieldName)
|
|
||||||
&& !"Proxy-Authenticate".equalsIgnoreCase(fieldName)
|
|
||||||
&& !"Proxy-Authorization".equalsIgnoreCase(fieldName)
|
|
||||||
&& !"TE".equalsIgnoreCase(fieldName)
|
|
||||||
&& !"Trailers".equalsIgnoreCase(fieldName)
|
|
||||||
&& !"Transfer-Encoding".equalsIgnoreCase(fieldName)
|
|
||||||
&& !"Upgrade".equalsIgnoreCase(fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse RFC 2617 challenges. This API is only interested in the scheme name and realm.
|
|
||||||
*/
|
|
||||||
public static List<Challenge> parseChallenges(Headers responseHeaders, String challengeHeader) {
|
public static List<Challenge> parseChallenges(Headers responseHeaders, String challengeHeader) {
|
||||||
// auth-scheme = token
|
// auth-scheme = token
|
||||||
// auth-param = token "=" ( token | quoted-string )
|
// auth-param = token "=" ( token | quoted-string )
|
||||||
@@ -172,10 +155,10 @@ public final class OkHeaders {
|
|||||||
int pos = 0;
|
int pos = 0;
|
||||||
while (pos < value.length()) {
|
while (pos < value.length()) {
|
||||||
int tokenStart = pos;
|
int tokenStart = pos;
|
||||||
pos = HeaderParser.skipUntil(value, pos, " ");
|
pos = skipUntil(value, pos, " ");
|
||||||
|
|
||||||
String scheme = value.substring(tokenStart, pos).trim();
|
String scheme = value.substring(tokenStart, pos).trim();
|
||||||
pos = HeaderParser.skipWhitespace(value, pos);
|
pos = skipWhitespace(value, pos);
|
||||||
|
|
||||||
// TODO: This currently only handles schemes with a 'realm' parameter;
|
// TODO: This currently only handles schemes with a 'realm' parameter;
|
||||||
// It needs to be fixed to handle any scheme and any parameters
|
// It needs to be fixed to handle any scheme and any parameters
|
||||||
@@ -187,12 +170,12 @@ public final class OkHeaders {
|
|||||||
|
|
||||||
pos += "realm=\"".length();
|
pos += "realm=\"".length();
|
||||||
int realmStart = pos;
|
int realmStart = pos;
|
||||||
pos = HeaderParser.skipUntil(value, pos, "\"");
|
pos = skipUntil(value, pos, "\"");
|
||||||
String realm = value.substring(realmStart, pos);
|
String realm = value.substring(realmStart, pos);
|
||||||
pos++; // Consume '"' close quote.
|
pos++; // Consume '"' close quote.
|
||||||
pos = HeaderParser.skipUntil(value, pos, ",");
|
pos = skipUntil(value, pos, ",");
|
||||||
pos++; // Consume ',' comma.
|
pos++; // Consume ',' comma.
|
||||||
pos = HeaderParser.skipWhitespace(value, pos);
|
pos = skipWhitespace(value, pos);
|
||||||
result.add(new Challenge(scheme, realm));
|
result.add(new Challenge(scheme, realm));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,4 +214,50 @@ public final class OkHeaders {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the next index in {@code input} at or after {@code pos} that contains a character from
|
||||||
|
* {@code characters}. Returns the input length if none of the requested characters can be found.
|
||||||
|
*/
|
||||||
|
public static int skipUntil(String input, int pos, String characters) {
|
||||||
|
for (; pos < input.length(); pos++) {
|
||||||
|
if (characters.indexOf(input.charAt(pos)) != -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the next non-whitespace character in {@code input} that is white space. Result is
|
||||||
|
* undefined if input contains newline characters.
|
||||||
|
*/
|
||||||
|
public static int skipWhitespace(String input, int pos) {
|
||||||
|
for (; pos < input.length(); pos++) {
|
||||||
|
char c = input.charAt(pos);
|
||||||
|
if (c != ' ' && c != '\t') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code value} as a positive integer, or 0 if it is negative, or {@code defaultValue} if
|
||||||
|
* it cannot be parsed.
|
||||||
|
*/
|
||||||
|
public static int parseSeconds(String value, int defaultValue) {
|
||||||
|
try {
|
||||||
|
long seconds = Long.parseLong(value);
|
||||||
|
if (seconds > Integer.MAX_VALUE) {
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
} else if (seconds < 0) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return (int) seconds;
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@@ -22,6 +22,7 @@ import okhttp3.HttpUrl;
|
|||||||
import okhttp3.Interceptor;
|
import okhttp3.Interceptor;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
import okhttp3.internal.connection.StreamAllocation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A concrete interceptor chain that carries the entire interceptor chain: all application
|
* A concrete interceptor chain that carries the entire interceptor chain: all application
|
||||||
|
@@ -35,7 +35,7 @@ public final class RealResponseBody extends ResponseBody {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public long contentLength() {
|
@Override public long contentLength() {
|
||||||
return OkHeaders.contentLength(headers);
|
return HttpHeaders.contentLength(headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public BufferedSource source() {
|
@Override public BufferedSource source() {
|
||||||
|
@@ -35,6 +35,8 @@ import okhttp3.OkHttpClient;
|
|||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.Route;
|
import okhttp3.Route;
|
||||||
|
import okhttp3.internal.connection.RouteException;
|
||||||
|
import okhttp3.internal.connection.StreamAllocation;
|
||||||
|
|
||||||
import static java.net.HttpURLConnection.HTTP_CLIENT_TIMEOUT;
|
import static java.net.HttpURLConnection.HTTP_CLIENT_TIMEOUT;
|
||||||
import static java.net.HttpURLConnection.HTTP_MOVED_PERM;
|
import static java.net.HttpURLConnection.HTTP_MOVED_PERM;
|
||||||
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal;
|
package okhttp3.internal.platform;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -30,6 +30,7 @@ import javax.net.ssl.SSLSocket;
|
|||||||
import javax.net.ssl.SSLSocketFactory;
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
import okhttp3.Protocol;
|
import okhttp3.Protocol;
|
||||||
|
import okhttp3.internal.Util;
|
||||||
import okhttp3.internal.tls.CertificateChainCleaner;
|
import okhttp3.internal.tls.CertificateChainCleaner;
|
||||||
|
|
||||||
/** Android 2.3 or better. */
|
/** Android 2.3 or better. */
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal;
|
package okhttp3.internal.platform;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal;
|
package okhttp3.internal.platform;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationHandler;
|
import java.lang.reflect.InvocationHandler;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
@@ -22,6 +22,7 @@ import java.lang.reflect.Proxy;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.net.ssl.SSLSocket;
|
import javax.net.ssl.SSLSocket;
|
||||||
import okhttp3.Protocol;
|
import okhttp3.Protocol;
|
||||||
|
import okhttp3.internal.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OpenJDK 7 or OpenJDK 8 with {@code org.mortbay.jetty.alpn/alpn-boot} in the boot class path.
|
* OpenJDK 7 or OpenJDK 8 with {@code org.mortbay.jetty.alpn/alpn-boot} in the boot class path.
|
@@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package okhttp3.internal;
|
package okhttp3.internal.platform;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
@@ -14,7 +14,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal;
|
package okhttp3.internal.platform;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
@@ -21,7 +21,7 @@ import java.security.cert.X509Certificate;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
import okhttp3.internal.Platform;
|
import okhttp3.internal.platform.Platform;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes the effective certificate chain from the raw array returned by Java's built in TLS APIs.
|
* Computes the effective certificate chain from the raw array returned by Java's built in TLS APIs.
|
||||||
|
Reference in New Issue
Block a user