mirror of
https://github.com/square/okhttp.git
synced 2025-12-25 00:01:02 +03:00
Sort imports and wrap documentation at 100 columns.
This is a mechanical refactoring. The only thing I had trouble with is IntelliJ's weak support for <ul> tags in Javadoc.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
@@ -88,7 +90,7 @@
|
||||
<argument>-Xmx512m</argument>
|
||||
<commandlineArgs>-Xbootclasspath/p:${bootclasspath}</commandlineArgs>
|
||||
<argument>-classpath</argument>
|
||||
<classpath />
|
||||
<classpath/>
|
||||
<argument>okhttp3.benchmarks.Benchmark</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package okhttp3.benchmarks;
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
|
||||
@@ -18,13 +18,6 @@ package okhttp3.benchmarks;
|
||||
import com.google.caliper.Param;
|
||||
import com.google.caliper.model.ArbitraryMeasurement;
|
||||
import com.google.caliper.runner.CaliperMain;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.mockwebserver.Dispatcher;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -34,13 +27,20 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.mockwebserver.Dispatcher;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import okio.Buffer;
|
||||
import okio.GzipSink;
|
||||
|
||||
/**
|
||||
* This benchmark is fake, but may be useful for certain relative comparisons.
|
||||
* It uses a local connection to a MockWebServer to measure how many identical
|
||||
* requests per second can be carried over a fixed number of threads.
|
||||
* This benchmark is fake, but may be useful for certain relative comparisons. It uses a local
|
||||
* connection to a MockWebServer to measure how many identical requests per second can be carried
|
||||
* over a fixed number of threads.
|
||||
*/
|
||||
public class Benchmark extends com.google.caliper.Benchmark {
|
||||
private static final int NUM_REPORTS = 10;
|
||||
@@ -48,16 +48,16 @@ public class Benchmark extends com.google.caliper.Benchmark {
|
||||
|
||||
private final Random random = new Random(0);
|
||||
|
||||
/** Which client to run.*/
|
||||
/** Which client to run. */
|
||||
@Param
|
||||
Client client;
|
||||
|
||||
/** How many concurrent requests to execute. */
|
||||
@Param({ "1", "10" })
|
||||
@Param({"1", "10"})
|
||||
int concurrencyLevel;
|
||||
|
||||
/** How many requests to enqueue to await threads to execute them. */
|
||||
@Param({ "10" })
|
||||
@Param({"10"})
|
||||
int targetBacklog;
|
||||
|
||||
/** True to use TLS. */
|
||||
@@ -74,11 +74,11 @@ public class Benchmark extends com.google.caliper.Benchmark {
|
||||
boolean chunked;
|
||||
|
||||
/** The size of the HTTP response body, in uncompressed bytes. */
|
||||
@Param({ "128", "1048576" })
|
||||
@Param({"128", "1048576"})
|
||||
int bodyByteCount;
|
||||
|
||||
/** How many additional headers were included, beyond the built-in ones. */
|
||||
@Param({ "0", "20" })
|
||||
@Param({"0", "20"})
|
||||
int headerCount;
|
||||
|
||||
/** Which ALPN protocols are in use. Only useful with TLS. */
|
||||
|
||||
@@ -20,6 +20,8 @@ import okhttp3.HttpUrl;
|
||||
/** An HTTP client to benchmark. */
|
||||
interface HttpClient {
|
||||
void prepare(Benchmark benchmark);
|
||||
|
||||
void enqueue(HttpUrl url) throws Exception;
|
||||
|
||||
boolean acceptingJobs();
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package okhttp3.benchmarks;
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.PooledByteBufAllocator;
|
||||
@@ -46,6 +44,8 @@ import java.util.Deque;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLEngine;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
|
||||
/** Netty isn't an HTTP client, but it's almost one. */
|
||||
class NettyHttpClient implements HttpClient {
|
||||
|
||||
@@ -15,18 +15,18 @@
|
||||
*/
|
||||
package okhttp3.benchmarks;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
|
||||
class OkHttp extends SynchronousHttpClient {
|
||||
private static final boolean VERBOSE = false;
|
||||
|
||||
@@ -15,14 +15,6 @@
|
||||
*/
|
||||
package okhttp3.benchmarks;
|
||||
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Dispatcher;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
@@ -32,6 +24,14 @@ import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Dispatcher;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
|
||||
class OkHttpAsync implements HttpClient {
|
||||
private static final boolean VERBOSE = false;
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package okhttp3.benchmarks;
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
/** Any HTTP client with a blocking API. */
|
||||
abstract class SynchronousHttpClient implements HttpClient {
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package okhttp3.benchmarks;
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
@@ -27,6 +25,8 @@ import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
|
||||
class UrlConnection extends SynchronousHttpClient {
|
||||
private static final boolean VERBOSE = false;
|
||||
|
||||
@@ -82,7 +82,15 @@
|
||||
<module name="ParenPad"/>
|
||||
<module name="TypecastParenPad"/>
|
||||
<module name="WhitespaceAfter"/>
|
||||
<module name="WhitespaceAround"/>
|
||||
<module name="WhitespaceAround">
|
||||
<property name="tokens"
|
||||
value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN,
|
||||
COLON, DIV, DIV_ASSIGN, DO_WHILE, EQUAL, GE, GT, LAND, LCURLY, LE, LITERAL_CATCH,
|
||||
LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
|
||||
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS,
|
||||
MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, SL, SLIST,
|
||||
SL_ASSIGN, SR, SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND"/>
|
||||
</module>
|
||||
|
||||
|
||||
<!-- Modifier Checks -->
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
|
||||
@@ -16,17 +16,6 @@
|
||||
package okhttp3.curl;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import okhttp3.ConnectionPool;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.internal.http.StatusLine;
|
||||
import okhttp3.internal.framed.Http2;
|
||||
|
||||
import io.airlift.command.Arguments;
|
||||
import io.airlift.command.Command;
|
||||
import io.airlift.command.HelpOption;
|
||||
@@ -49,6 +38,16 @@ import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import okhttp3.ConnectionPool;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.internal.framed.Http2;
|
||||
import okhttp3.internal.http.StatusLine;
|
||||
import okio.BufferedSource;
|
||||
import okio.Okio;
|
||||
import okio.Sink;
|
||||
@@ -84,16 +83,16 @@ public class Main extends HelpOption implements Runnable {
|
||||
return Joiner.on(", ").join(Protocol.values());
|
||||
}
|
||||
|
||||
@Option(name = { "-X", "--request" }, description = "Specify request command to use")
|
||||
@Option(name = {"-X", "--request"}, description = "Specify request command to use")
|
||||
public String method;
|
||||
|
||||
@Option(name = { "-d", "--data" }, description = "HTTP POST data")
|
||||
@Option(name = {"-d", "--data"}, description = "HTTP POST data")
|
||||
public String data;
|
||||
|
||||
@Option(name = { "-H", "--header" }, description = "Custom header to pass to server")
|
||||
@Option(name = {"-H", "--header"}, description = "Custom header to pass to server")
|
||||
public List<String> headers;
|
||||
|
||||
@Option(name = { "-A", "--user-agent" }, description = "User-Agent to send to server")
|
||||
@Option(name = {"-A", "--user-agent"}, description = "User-Agent to send to server")
|
||||
public String userAgent = NAME + "/" + versionString();
|
||||
|
||||
@Option(name = "--connect-timeout", description = "Maximum time allowed for connection (seconds)")
|
||||
@@ -102,23 +101,23 @@ public class Main extends HelpOption implements Runnable {
|
||||
@Option(name = "--read-timeout", description = "Maximum time allowed for reading data (seconds)")
|
||||
public int readTimeout = DEFAULT_TIMEOUT;
|
||||
|
||||
@Option(name = { "-L", "--location" }, description = "Follow redirects")
|
||||
@Option(name = {"-L", "--location"}, description = "Follow redirects")
|
||||
public boolean followRedirects;
|
||||
|
||||
@Option(name = { "-k", "--insecure" },
|
||||
@Option(name = {"-k", "--insecure"},
|
||||
description = "Allow connections to SSL sites without certs")
|
||||
public boolean allowInsecure;
|
||||
|
||||
@Option(name = { "-i", "--include" }, description = "Include protocol headers in the output")
|
||||
@Option(name = {"-i", "--include"}, description = "Include protocol headers in the output")
|
||||
public boolean showHeaders;
|
||||
|
||||
@Option(name = "--frames", description = "Log HTTP/2 frames to STDERR")
|
||||
public boolean showHttp2Frames;
|
||||
|
||||
@Option(name = { "-e", "--referer" }, description = "Referer URL")
|
||||
@Option(name = {"-e", "--referer"}, description = "Referer URL")
|
||||
public String referer;
|
||||
|
||||
@Option(name = { "-V", "--version" }, description = "Show version number and quit")
|
||||
@Option(name = {"-V", "--version"}, description = "Show version number and quit")
|
||||
public boolean version;
|
||||
|
||||
@Arguments(title = "url", description = "Remote resource URL")
|
||||
@@ -258,7 +257,7 @@ public class Main extends HelpOption implements Runnable {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
context.init(null, new TrustManager[] { permissive }, null);
|
||||
context.init(null, new TrustManager[] {permissive}, null);
|
||||
return context.getSocketFactory();
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError(e);
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
package okhttp3.curl;
|
||||
|
||||
import java.io.IOException;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import java.io.IOException;
|
||||
import okio.Buffer;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
@@ -11,7 +13,9 @@
|
||||
|
||||
<artifactId>okhttp-android-support</artifactId>
|
||||
<name>OkHttp Android Platform Support</name>
|
||||
<description>Classes to support the Android platform's use of OkHttp (not required for most developers).</description>
|
||||
<description>Classes to support the Android platform's use of OkHttp (not required for most
|
||||
developers).
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
*/
|
||||
package okhttp3;
|
||||
|
||||
import okhttp3.internal.huc.CacheAdapter;
|
||||
|
||||
import java.net.ResponseCache;
|
||||
import okhttp3.internal.huc.CacheAdapter;
|
||||
|
||||
/**
|
||||
* Back doors to enable the use of OkHttp within the Android platform libraries. OkHttp is used to
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package okhttp3;
|
||||
|
||||
import okhttp3.internal.huc.JavaApiConverter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.CacheRequest;
|
||||
@@ -26,6 +24,7 @@ import java.net.URI;
|
||||
import java.net.URLConnection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import okhttp3.internal.huc.JavaApiConverter;
|
||||
|
||||
/**
|
||||
* A class provided for use by Android so that it can continue supporting a {@link ResponseCache}
|
||||
@@ -80,60 +79,55 @@ public class AndroidShimResponseCache extends ResponseCache {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of bytes currently being used to store the values in
|
||||
* this cache. This may be greater than the {@link #maxSize} if a background
|
||||
* deletion is pending.
|
||||
* Returns the number of bytes currently being used to store the values in this cache. This may be
|
||||
* greater than the {@link #maxSize} if a background deletion is pending.
|
||||
*/
|
||||
public long size() throws IOException {
|
||||
return delegate.getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum number of bytes that this cache should use to store
|
||||
* its data.
|
||||
* Returns the maximum number of bytes that this cache should use to store its data.
|
||||
*/
|
||||
public long maxSize() {
|
||||
return delegate.getMaxSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Force buffered operations to the filesystem. This ensures that responses
|
||||
* written to the cache will be available the next time the cache is opened,
|
||||
* even if this process is killed.
|
||||
* Force buffered operations to the filesystem. This ensures that responses written to the cache
|
||||
* will be available the next time the cache is opened, even if this process is killed.
|
||||
*/
|
||||
public void flush() throws IOException {
|
||||
delegate.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of HTTP requests that required the network to either
|
||||
* supply a response or validate a locally cached response.
|
||||
* Returns the number of HTTP requests that required the network to either supply a response or
|
||||
* validate a locally cached response.
|
||||
*/
|
||||
public int getNetworkCount() {
|
||||
return delegate.getNetworkCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of HTTP requests whose response was provided by the
|
||||
* cache. This may include conditional {@code GET} requests that were
|
||||
* validated over the network.
|
||||
* Returns the number of HTTP requests whose response was provided by the cache. This may include
|
||||
* conditional {@code GET} requests that were validated over the network.
|
||||
*/
|
||||
public int getHitCount() {
|
||||
return delegate.getHitCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total number of HTTP requests that were made. This includes
|
||||
* both client requests and requests that were made on the client's behalf
|
||||
* to handle a redirects and retries.
|
||||
* Returns the total number of HTTP requests that were made. This includes both client requests
|
||||
* and requests that were made on the client's behalf to handle a redirects and retries.
|
||||
*/
|
||||
public int getRequestCount() {
|
||||
return delegate.getRequestCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstalls the cache and releases any active resources. Stored contents
|
||||
* will remain on the filesystem.
|
||||
* Uninstalls the cache and releases any active resources. Stored contents will remain on the
|
||||
* filesystem.
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
delegate.close();
|
||||
@@ -145,5 +139,4 @@ public class AndroidShimResponseCache extends ResponseCache {
|
||||
public void delete() throws IOException {
|
||||
delegate.delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
package okhttp3;
|
||||
|
||||
/**
|
||||
* An interface that allows OkHttp to detect that a {@link java.net.ResponseCache} contains a
|
||||
* {@link Cache}.
|
||||
* An interface that allows OkHttp to detect that a {@link java.net.ResponseCache} contains a {@link
|
||||
* Cache}.
|
||||
*/
|
||||
public interface OkCacheContainer {
|
||||
Cache getCache();
|
||||
|
||||
@@ -15,11 +15,6 @@
|
||||
*/
|
||||
package okhttp3.internal.huc;
|
||||
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.internal.InternalCache;
|
||||
import okhttp3.internal.http.CacheRequest;
|
||||
import okhttp3.internal.http.CacheStrategy;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.CacheResponse;
|
||||
@@ -28,6 +23,11 @@ import java.net.ResponseCache;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.internal.InternalCache;
|
||||
import okhttp3.internal.http.CacheRequest;
|
||||
import okhttp3.internal.http.CacheStrategy;
|
||||
import okio.Okio;
|
||||
import okio.Sink;
|
||||
|
||||
@@ -95,8 +95,8 @@ public final class CacheAdapter implements InternalCache {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link CacheResponse} from the delegate by converting the
|
||||
* OkHttp {@link Request} into the arguments required by the {@link ResponseCache}.
|
||||
* Returns the {@link CacheResponse} from the delegate by converting the OkHttp {@link Request}
|
||||
* into the arguments required by the {@link ResponseCache}.
|
||||
*/
|
||||
private CacheResponse getJavaCachedResponse(Request request) throws IOException {
|
||||
Map<String, List<String>> headers = JavaApiConverter.extractJavaHeaders(request);
|
||||
|
||||
@@ -15,20 +15,6 @@
|
||||
*/
|
||||
package okhttp3.internal.huc;
|
||||
|
||||
import okhttp3.CipherSuite;
|
||||
import okhttp3.Handshake;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.internal.http.CacheRequest;
|
||||
import okhttp3.internal.http.HttpMethod;
|
||||
import okhttp3.internal.http.OkHeaders;
|
||||
import okhttp3.internal.http.StatusLine;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -48,6 +34,20 @@ import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import okhttp3.CipherSuite;
|
||||
import okhttp3.Handshake;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.internal.http.CacheRequest;
|
||||
import okhttp3.internal.http.HttpMethod;
|
||||
import okhttp3.internal.http.OkHeaders;
|
||||
import okhttp3.internal.http.StatusLine;
|
||||
import okio.BufferedSource;
|
||||
import okio.Okio;
|
||||
import okio.Sink;
|
||||
@@ -62,9 +62,9 @@ public final class JavaApiConverter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an OkHttp {@link Response} using the supplied {@link URI} and {@link URLConnection}
|
||||
* to supply the data. The URLConnection is assumed to already be connected. If this method
|
||||
* returns {@code null} the response is uncacheable.
|
||||
* Creates an OkHttp {@link Response} using the supplied {@link URI} and {@link URLConnection} to
|
||||
* supply the data. The URLConnection is assumed to already be connected. If this method returns
|
||||
* {@code null} the response is uncacheable.
|
||||
*/
|
||||
public static Response createOkResponseForCachePut(URI uri, URLConnection urlConnection)
|
||||
throws IOException {
|
||||
@@ -264,9 +264,9 @@ public final class JavaApiConverter {
|
||||
/**
|
||||
* Creates an OkHttp {@link Request} from the supplied information.
|
||||
*
|
||||
* <p>This method allows a {@code null} value for {@code requestHeaders} for situations
|
||||
* where a connection is already connected and access to the headers has been lost.
|
||||
* See {@link java.net.HttpURLConnection#getRequestProperties()} for details.
|
||||
* <p>This method allows a {@code null} value for {@code requestHeaders} for situations where a
|
||||
* connection is already connected and access to the headers has been lost. See {@link
|
||||
* java.net.HttpURLConnection#getRequestProperties()} for details.
|
||||
*/
|
||||
public static Request createOkRequest(
|
||||
URI uri, String requestMethod, Map<String, List<String>> requestHeaders) {
|
||||
@@ -287,8 +287,8 @@ public final class JavaApiConverter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link java.net.CacheResponse} of the correct (sub)type using information
|
||||
* gathered from the supplied {@link Response}.
|
||||
* Creates a {@link java.net.CacheResponse} of the correct (sub)type using information gathered
|
||||
* from the supplied {@link Response}.
|
||||
*/
|
||||
public static CacheResponse createJavaCacheResponse(final Response response) {
|
||||
final Headers headers = response.headers();
|
||||
@@ -364,6 +364,7 @@ public final class JavaApiConverter {
|
||||
public void abort() {
|
||||
okCacheRequest.abort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getBody() throws IOException {
|
||||
Sink body = okCacheRequest.body();
|
||||
@@ -415,8 +416,8 @@ public final class JavaApiConverter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts OkHttp headers from the supplied {@link Map}. Only real headers are
|
||||
* extracted. Any entry (one with a {@code null} key) is discarded.
|
||||
* Extracts OkHttp headers from the supplied {@link Map}. Only real headers are extracted. Any
|
||||
* entry (one with a {@code null} key) is discarded.
|
||||
*/
|
||||
// @VisibleForTesting
|
||||
static Headers extractOkHeaders(Map<String, List<String>> javaHeaders) {
|
||||
@@ -438,9 +439,9 @@ public final class JavaApiConverter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the status line from the supplied Java API {@link java.net.HttpURLConnection}.
|
||||
* As per the spec, the status line is held as the header with the null key. Returns {@code null}
|
||||
* if there is no status line.
|
||||
* Extracts the status line from the supplied Java API {@link java.net.HttpURLConnection}. As per
|
||||
* the spec, the status line is held as the header with the null key. Returns {@code null} if
|
||||
* there is no status line.
|
||||
*/
|
||||
private static String extractStatusLine(HttpURLConnection httpUrlConnection) {
|
||||
// Java specifies that this will be be response header with a null key.
|
||||
@@ -448,9 +449,9 @@ public final class JavaApiConverter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the status line from the supplied Java API {@link java.net.CacheResponse}.
|
||||
* As per the spec, the status line is held as the header with the null key. Throws a
|
||||
* {@link ProtocolException} if there is no status line.
|
||||
* Extracts the status line from the supplied Java API {@link java.net.CacheResponse}. As per the
|
||||
* spec, the status line is held as the header with the null key. Throws a {@link
|
||||
* ProtocolException} if there is no status line.
|
||||
*/
|
||||
private static String extractStatusLine(CacheResponse javaResponse) throws IOException {
|
||||
Map<String, List<String>> javaResponseHeaders = javaResponse.getHeaders();
|
||||
@@ -487,6 +488,7 @@ public final class JavaApiConverter {
|
||||
public long contentLength() {
|
||||
return OkHeaders.contentLength(okHeaders);
|
||||
}
|
||||
|
||||
@Override public BufferedSource source() {
|
||||
return body;
|
||||
}
|
||||
@@ -507,10 +509,12 @@ public final class JavaApiConverter {
|
||||
String contentTypeHeader = urlConnection.getContentType();
|
||||
return contentTypeHeader == null ? null : MediaType.parse(contentTypeHeader);
|
||||
}
|
||||
|
||||
@Override public long contentLength() {
|
||||
String s = urlConnection.getHeaderField("Content-Length");
|
||||
return stringToLong(s);
|
||||
}
|
||||
|
||||
@Override public BufferedSource source() {
|
||||
return body;
|
||||
}
|
||||
@@ -518,10 +522,10 @@ public final class JavaApiConverter {
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@link java.net.HttpURLConnection} that represents an HTTP request at the point where
|
||||
* the request has been made, and the response headers have been received, but the body content,
|
||||
* if present, has not been read yet. This intended to provide enough information for
|
||||
* {@link java.net.ResponseCache} subclasses and no more.
|
||||
* An {@link java.net.HttpURLConnection} that represents an HTTP request at the point where the
|
||||
* request has been made, and the response headers have been received, but the body content, if
|
||||
* present, has not been read yet. This intended to provide enough information for {@link
|
||||
* java.net.ResponseCache} subclasses and no more.
|
||||
*
|
||||
* <p>Much of the method implementations are overrides to delegate to the OkHttp request and
|
||||
* response, or to deny access to information as a real HttpURLConnection would after connection.
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
package okhttp3.android;
|
||||
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.AndroidShimResponseCache;
|
||||
import okhttp3.OkCacheContainer;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -30,15 +26,18 @@ import java.net.URI;
|
||||
import java.net.URLConnection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import okhttp3.AndroidShimResponseCache;
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.OkCacheContainer;
|
||||
|
||||
/**
|
||||
* A copy of android.net.http.HttpResponseCache taken from AOSP. Android need to keep this code
|
||||
* working somehow. Dependencies on okhttp3 are com.android.okhttp on Android.
|
||||
*
|
||||
* <p>This class exists in okhttp-android-support to help keep the API as it always has been on
|
||||
* Android. The public API cannot be changed. This class delegates to
|
||||
* {@link AndroidShimResponseCache}, a class that exists in a package that
|
||||
* enables it to interact with non-public OkHttp classes.
|
||||
* Android. The public API cannot be changed. This class delegates to {@link
|
||||
* AndroidShimResponseCache}, a class that exists in a package that enables it to interact with
|
||||
* non-public OkHttp classes.
|
||||
*/
|
||||
public final class HttpResponseCache extends ResponseCache implements Closeable, OkCacheContainer {
|
||||
|
||||
@@ -49,8 +48,8 @@ public final class HttpResponseCache extends ResponseCache implements Closeable,
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently-installed {@code HttpResponseCache}, or null if
|
||||
* there is no cache installed or it is not a {@code HttpResponseCache}.
|
||||
* Returns the currently-installed {@code HttpResponseCache}, or null if there is no cache
|
||||
* installed or it is not a {@code HttpResponseCache}.
|
||||
*/
|
||||
public static HttpResponseCache getInstalled() {
|
||||
ResponseCache installed = ResponseCache.getDefault();
|
||||
@@ -66,9 +65,8 @@ public final class HttpResponseCache extends ResponseCache implements Closeable,
|
||||
* @param directory the directory to hold cache data.
|
||||
* @param maxSize the maximum size of the cache in bytes.
|
||||
* @return the newly-installed cache
|
||||
* @throws java.io.IOException if {@code directory} cannot be used for this cache.
|
||||
* Most applications should respond to this exception by logging a
|
||||
* warning.
|
||||
* @throws java.io.IOException if {@code directory} cannot be used for this cache. Most
|
||||
* applications should respond to this exception by logging a warning.
|
||||
*/
|
||||
public static synchronized HttpResponseCache install(File directory, long maxSize) throws
|
||||
IOException {
|
||||
@@ -103,9 +101,8 @@ public final class HttpResponseCache extends ResponseCache implements Closeable,
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of bytes currently being used to store the values in
|
||||
* this cache. This may be greater than the {@link #maxSize} if a background
|
||||
* deletion is pending.
|
||||
* Returns the number of bytes currently being used to store the values in this cache. This may be
|
||||
* greater than the {@link #maxSize} if a background deletion is pending.
|
||||
*/
|
||||
public long size() {
|
||||
try {
|
||||
@@ -117,17 +114,15 @@ public final class HttpResponseCache extends ResponseCache implements Closeable,
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum number of bytes that this cache should use to store
|
||||
* its data.
|
||||
* Returns the maximum number of bytes that this cache should use to store its data.
|
||||
*/
|
||||
public long maxSize() {
|
||||
return shimResponseCache.maxSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Force buffered operations to the filesystem. This ensures that responses
|
||||
* written to the cache will be available the next time the cache is opened,
|
||||
* even if this process is killed.
|
||||
* Force buffered operations to the filesystem. This ensures that responses written to the cache
|
||||
* will be available the next time the cache is opened, even if this process is killed.
|
||||
*/
|
||||
public void flush() {
|
||||
try {
|
||||
@@ -137,34 +132,32 @@ public final class HttpResponseCache extends ResponseCache implements Closeable,
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of HTTP requests that required the network to either
|
||||
* supply a response or validate a locally cached response.
|
||||
* Returns the number of HTTP requests that required the network to either supply a response or
|
||||
* validate a locally cached response.
|
||||
*/
|
||||
public int getNetworkCount() {
|
||||
return shimResponseCache.getNetworkCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of HTTP requests whose response was provided by the
|
||||
* cache. This may include conditional {@code GET} requests that were
|
||||
* validated over the network.
|
||||
* Returns the number of HTTP requests whose response was provided by the cache. This may include
|
||||
* conditional {@code GET} requests that were validated over the network.
|
||||
*/
|
||||
public int getHitCount() {
|
||||
return shimResponseCache.getHitCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total number of HTTP requests that were made. This includes
|
||||
* both client requests and requests that were made on the client's behalf
|
||||
* to handle a redirects and retries.
|
||||
* Returns the total number of HTTP requests that were made. This includes both client requests
|
||||
* and requests that were made on the client's behalf to handle a redirects and retries.
|
||||
*/
|
||||
public int getRequestCount() {
|
||||
return shimResponseCache.getRequestCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstalls the cache and releases any active resources. Stored contents
|
||||
* will remain on the filesystem.
|
||||
* Uninstalls the cache and releases any active resources. Stored contents will remain on the
|
||||
* filesystem.
|
||||
*/
|
||||
@Override public void close() throws IOException {
|
||||
if (ResponseCache.getDefault() == this) {
|
||||
@@ -187,5 +180,4 @@ public final class HttpResponseCache extends ResponseCache implements Closeable,
|
||||
public Cache getCache() {
|
||||
return shimResponseCache.getCache();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,12 +16,6 @@
|
||||
|
||||
package okhttp3.android;
|
||||
|
||||
import okhttp3.AndroidInternal;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.CacheRequest;
|
||||
@@ -31,6 +25,12 @@ import java.net.URI;
|
||||
import java.net.URLConnection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import okhttp3.AndroidInternal;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -133,8 +133,8 @@ public final class HttpResponseCacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that statistics tracking are wired all the way through the
|
||||
* wrapper class. http://code.google.com/p/android/issues/detail?id=25418
|
||||
* Make sure that statistics tracking are wired all the way through the wrapper class.
|
||||
* http://code.google.com/p/android/issues/detail?id=25418
|
||||
*/
|
||||
@Test public void statisticsTracking() throws Exception {
|
||||
HttpResponseCache cache = HttpResponseCache.install(cacheDir, 10 * 1024 * 1024);
|
||||
|
||||
@@ -15,14 +15,6 @@
|
||||
*/
|
||||
package okhttp3.internal.huc;
|
||||
|
||||
import okhttp3.AbstractResponseCache;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.testing.RecordingHostnameVerifier;
|
||||
import java.io.IOException;
|
||||
import java.net.CacheRequest;
|
||||
import java.net.CacheResponse;
|
||||
@@ -38,6 +30,14 @@ import java.util.Map;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import okhttp3.AbstractResponseCache;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.testing.RecordingHostnameVerifier;
|
||||
import okio.Buffer;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -52,9 +52,9 @@ import static org.junit.Assert.assertTrue;
|
||||
* A white-box test for {@link CacheAdapter}. See also:
|
||||
* <ul>
|
||||
* <li>{@link ResponseCacheTest} for black-box tests that check that {@link ResponseCache}
|
||||
* classes are called correctly by OkHttp.</li>
|
||||
* classes are called correctly by OkHttp.
|
||||
* <li>{@link JavaApiConverterTest} for tests that check Java API classes / OkHttp conversion
|
||||
* logic. </li>
|
||||
* logic.
|
||||
* </ul>
|
||||
*/
|
||||
public class CacheAdapterTest {
|
||||
@@ -81,8 +81,8 @@ public class CacheAdapterTest {
|
||||
assertEquals("http", serverUrl.getProtocol());
|
||||
|
||||
ResponseCache responseCache = new AbstractResponseCache() {
|
||||
@Override
|
||||
public CacheResponse get(URI uri, String method, Map<String, List<String>> headers) throws IOException {
|
||||
@Override public CacheResponse get(
|
||||
URI uri, String method, Map<String, List<String>> headers) throws IOException {
|
||||
assertEquals(toUri(serverUrl), uri);
|
||||
assertEquals("GET", method);
|
||||
assertTrue("Arbitrary standard header not present", headers.containsKey("User-Agent"));
|
||||
@@ -214,7 +214,8 @@ public class CacheAdapterTest {
|
||||
assertEquals(serverUrl, connection.getURL());
|
||||
|
||||
HttpsURLConnection cacheHttpsUrlConnection = (HttpsURLConnection) connection;
|
||||
HttpsURLConnection realHttpsUrlConnection = (HttpsURLConnection) CacheAdapterTest.this.connection;
|
||||
HttpsURLConnection realHttpsUrlConnection =
|
||||
(HttpsURLConnection) CacheAdapterTest.this.connection;
|
||||
assertEquals(realHttpsUrlConnection.getCipherSuite(),
|
||||
cacheHttpsUrlConnection.getCipherSuite());
|
||||
assertEquals(realHttpsUrlConnection.getPeerPrincipal(),
|
||||
|
||||
@@ -15,18 +15,6 @@
|
||||
*/
|
||||
package okhttp3.internal.huc;
|
||||
|
||||
import okhttp3.CipherSuite;
|
||||
import okhttp3.Handshake;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -50,9 +38,20 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||
import okhttp3.CipherSuite;
|
||||
import okhttp3.Handshake;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSource;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -185,7 +184,8 @@ public class JavaApiConverterTest {
|
||||
return localCertificates;
|
||||
}
|
||||
|
||||
@Override public List<Certificate> getServerCertificateChain() throws SSLPeerUnverifiedException {
|
||||
@Override public List<Certificate> getServerCertificateChain()
|
||||
throws SSLPeerUnverifiedException {
|
||||
return serverCertificates;
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ public class JavaApiConverterTest {
|
||||
@Test public void createOkRequest_nullRequestHeaders() throws Exception {
|
||||
URI uri = new URI("http://foo/bar");
|
||||
|
||||
Map<String,List<String>> javaRequestHeaders = null;
|
||||
Map<String, List<String>> javaRequestHeaders = null;
|
||||
Request request = JavaApiConverter.createOkRequest(uri, "POST", javaRequestHeaders);
|
||||
assertFalse(request.isHttps());
|
||||
assertEquals(uri, request.url().uri());
|
||||
@@ -235,7 +235,7 @@ public class JavaApiConverterTest {
|
||||
@Test public void createOkRequest_nonNullRequestHeaders() throws Exception {
|
||||
URI uri = new URI("https://foo/bar");
|
||||
|
||||
Map<String,List<String>> javaRequestHeaders = new HashMap<>();
|
||||
Map<String, List<String>> javaRequestHeaders = new HashMap<>();
|
||||
javaRequestHeaders.put("Foo", Arrays.asList("Bar"));
|
||||
Request request = JavaApiConverter.createOkRequest(uri, "POST", javaRequestHeaders);
|
||||
assertTrue(request.isHttps());
|
||||
@@ -253,7 +253,7 @@ public class JavaApiConverterTest {
|
||||
@Test public void createOkRequest_nullRequestHeaderKey() throws Exception {
|
||||
URI uri = new URI("https://foo/bar");
|
||||
|
||||
Map<String,List<String>> javaRequestHeaders = new HashMap<>();
|
||||
Map<String, List<String>> javaRequestHeaders = new HashMap<>();
|
||||
javaRequestHeaders.put(null, Arrays.asList("GET / HTTP 1.1"));
|
||||
javaRequestHeaders.put("Foo", Arrays.asList("Bar"));
|
||||
Request request = JavaApiConverter.createOkRequest(uri, "POST", javaRequestHeaders);
|
||||
@@ -474,8 +474,8 @@ public class JavaApiConverterTest {
|
||||
|
||||
assertEquals("SSL_RSA_WITH_NULL_MD5", httpsUrlConnection.getCipherSuite());
|
||||
assertEquals(SERVER_CERT.getSubjectX500Principal(), httpsUrlConnection.getPeerPrincipal());
|
||||
assertArrayEquals(new Certificate[] { LOCAL_CERT }, httpsUrlConnection.getLocalCertificates());
|
||||
assertArrayEquals(new Certificate[] { SERVER_CERT },
|
||||
assertArrayEquals(new Certificate[] {LOCAL_CERT}, httpsUrlConnection.getLocalCertificates());
|
||||
assertArrayEquals(new Certificate[] {SERVER_CERT},
|
||||
httpsUrlConnection.getServerCertificates());
|
||||
assertEquals(LOCAL_CERT.getSubjectX500Principal(), httpsUrlConnection.getLocalPrincipal());
|
||||
}
|
||||
@@ -551,7 +551,7 @@ public class JavaApiConverterTest {
|
||||
Request okRequest =
|
||||
createArbitraryOkRequest().newBuilder()
|
||||
.url("https://secure/request")
|
||||
.post(createRequestBody("RequestBody") )
|
||||
.post(createRequestBody("RequestBody"))
|
||||
.build();
|
||||
ResponseBody responseBody = createResponseBody("ResponseBody");
|
||||
Handshake handshake = Handshake.get(null, CipherSuite.TLS_RSA_WITH_NULL_MD5,
|
||||
|
||||
@@ -16,18 +16,6 @@
|
||||
|
||||
package okhttp3.internal.huc;
|
||||
|
||||
import okhttp3.AbstractResponseCache;
|
||||
import okhttp3.AndroidInternal;
|
||||
import okhttp3.AndroidShimResponseCache;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import okhttp3.testing.RecordingHostnameVerifier;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -67,7 +55,19 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import okhttp3.AbstractResponseCache;
|
||||
import okhttp3.AndroidInternal;
|
||||
import okhttp3.AndroidShimResponseCache;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import okhttp3.mockwebserver.SocketPolicy;
|
||||
import okhttp3.testing.RecordingHostnameVerifier;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSink;
|
||||
import okio.GzipSink;
|
||||
@@ -86,8 +86,8 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Tests the interaction between OkHttp and {@link ResponseCache}.
|
||||
* Based on okhttp3.CacheTest with changes for ResponseCache and HttpURLConnection.
|
||||
* Tests the interaction between OkHttp and {@link ResponseCache}. Based on okhttp3.CacheTest with
|
||||
* changes for ResponseCache and HttpURLConnection.
|
||||
*/
|
||||
public final class ResponseCacheTest {
|
||||
@Rule public TemporaryFolder cacheRule = new TemporaryFolder();
|
||||
@@ -363,10 +363,9 @@ public final class ResponseCacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* We've had bugs where caching and cross-protocol redirects yield class
|
||||
* cast exceptions internal to the cache because we incorrectly assumed that
|
||||
* HttpsURLConnection was always HTTPS and HttpURLConnection was always HTTP;
|
||||
* in practice redirects mean that each can do either.
|
||||
* We've had bugs where caching and cross-protocol redirects yield class cast exceptions internal
|
||||
* to the cache because we incorrectly assumed that HttpsURLConnection was always HTTPS and
|
||||
* HttpURLConnection was always HTTP; in practice redirects mean that each can do either.
|
||||
*
|
||||
* https://github.com/square/okhttp/issues/214
|
||||
*/
|
||||
@@ -767,7 +766,8 @@ public final class ResponseCacheTest {
|
||||
/**
|
||||
* Equivalent to {@code CacheTest.postInvalidatesCacheWithUncacheableResponse()} but demonstrating
|
||||
* that {@link ResponseCache} provides no mechanism for cache invalidation as the result of
|
||||
* locally-made requests. In reality invalidation could take place from other clients at any time.
|
||||
* locally-made requests. In reality invalidation could take place from other clients at any
|
||||
* time.
|
||||
*/
|
||||
@Test public void postInvalidatesCacheWithUncacheableResponse() throws Exception {
|
||||
// 1. seed the cache
|
||||
@@ -1168,8 +1168,8 @@ public final class ResponseCacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* For Last-Modified and Date headers, we should echo the date back in the
|
||||
* exact format we were served.
|
||||
* For Last-Modified and Date headers, we should echo the date back in the exact format we were
|
||||
* served.
|
||||
*/
|
||||
@Test public void retainServedDateFormat() throws Exception {
|
||||
// Serve a response with a non-standard date format that OkHttp supports.
|
||||
@@ -1682,9 +1682,8 @@ public final class ResponseCacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param delta the offset from the current date to use. Negative
|
||||
* values yield dates in the past; positive values yield dates in the
|
||||
* future.
|
||||
* @param delta the offset from the current date to use. Negative values yield dates in the past;
|
||||
* positive values yield dates in the future.
|
||||
*/
|
||||
private String formatDate(long delta, TimeUnit timeUnit) {
|
||||
return formatDate(new Date(System.currentTimeMillis() + timeUnit.toMillis(delta)));
|
||||
@@ -1750,9 +1749,8 @@ public final class ResponseCacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortens the body of {@code response} but not the corresponding headers.
|
||||
* Only useful to test how clients respond to the premature conclusion of
|
||||
* the HTTP body.
|
||||
* Shortens the body of {@code response} but not the corresponding headers. Only useful to test
|
||||
* how clients respond to the premature conclusion of the HTTP body.
|
||||
*/
|
||||
private MockResponse truncateViolently(MockResponse response, int numBytesToKeep) {
|
||||
response.setSocketPolicy(SocketPolicy.DISCONNECT_AT_END);
|
||||
@@ -1801,9 +1799,8 @@ public final class ResponseCacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads {@code count} characters from the stream. If the stream is
|
||||
* exhausted before {@code count} characters can be read, the remaining
|
||||
* characters are returned and the stream is closed.
|
||||
* Reads {@code count} characters from the stream. If the stream is exhausted before {@code count}
|
||||
* characters can be read, the remaining characters are returned and the stream is closed.
|
||||
*/
|
||||
private String readAscii(URLConnection connection, int count) throws IOException {
|
||||
HttpURLConnection httpConnection = (HttpURLConnection) connection;
|
||||
@@ -1848,8 +1845,8 @@ public final class ResponseCacheTest {
|
||||
// Android-added tests.
|
||||
|
||||
/**
|
||||
* Test that we can interrogate the response when the cache is being
|
||||
* populated. http://code.google.com/p/android/issues/detail?id=7787
|
||||
* Test that we can interrogate the response when the cache is being populated.
|
||||
* http://code.google.com/p/android/issues/detail?id=7787
|
||||
*/
|
||||
@Test public void responseCacheCallbackApis() throws Exception {
|
||||
final String body = "ABCDE";
|
||||
@@ -1973,6 +1970,7 @@ public final class ResponseCacheTest {
|
||||
@Override public InputStream getBody() throws IOException {
|
||||
return response.getBody();
|
||||
}
|
||||
|
||||
@Override public Map<String, List<String>> getHeaders() throws IOException {
|
||||
return response.getHeaders();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package okhttp3.apache;
|
||||
|
||||
import java.io.IOException;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import java.io.IOException;
|
||||
import okio.BufferedSink;
|
||||
import org.apache.http.HttpEntity;
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
// Copyright 2013 Square, Inc.
|
||||
package okhttp3.apache;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
@@ -32,9 +32,9 @@ import static java.net.Proxy.Type.HTTP;
|
||||
import static org.apache.http.HttpVersion.HTTP_1_1;
|
||||
|
||||
/**
|
||||
* @deprecated OkHttp will be dropping its ability to be used with {@link HttpClient} in an
|
||||
* upcoming release. Applications that need this should either downgrade to the Apache
|
||||
* implementation or upgrade to OkHttp's Request/Response API.
|
||||
* @deprecated OkHttp will be dropping its ability to be used with {@link HttpClient} in an upcoming
|
||||
* release. Applications that need this should either downgrade to the Apache implementation or
|
||||
* upgrade to OkHttp's Request/Response API.
|
||||
*/
|
||||
public final class OkApacheClient implements HttpClient {
|
||||
private static Request transformRequest(HttpRequest request) {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package okhttp3.apache;
|
||||
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import okio.Buffer;
|
||||
import okio.GzipSink;
|
||||
import okio.Okio;
|
||||
@@ -114,6 +114,7 @@ public class OkApacheClientTest {
|
||||
assertEquals("Hello, world!", request.getBody().readUtf8());
|
||||
assertEquals(request.getHeader("Content-Length"), "13");
|
||||
}
|
||||
|
||||
@Test public void postEmptyEntity() throws Exception {
|
||||
server.enqueue(new MockResponse());
|
||||
final HttpPost post = new HttpPost(server.url("/").url().toURI());
|
||||
@@ -123,6 +124,7 @@ public class OkApacheClientTest {
|
||||
assertEquals(0, request.getBodySize());
|
||||
assertNotNull(request.getBody());
|
||||
}
|
||||
|
||||
@Test public void putEmptyEntity() throws Exception {
|
||||
server.enqueue(new MockResponse());
|
||||
final HttpPut put = new HttpPut(server.url("/").url().toURI());
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package okhttp3.internal.spdy;
|
||||
|
||||
import okhttp3.internal.spdy.hpackjson.Story;
|
||||
import java.util.Collection;
|
||||
import okhttp3.internal.spdy.hpackjson.Story;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
@@ -30,7 +30,7 @@ public class HpackDecodeInteropTest extends HpackDecodeTestBase {
|
||||
super(story);
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static Collection<Story[]> createStories() throws Exception {
|
||||
return createStories(storiesForCurrentDraft());
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package okhttp3.internal.spdy;
|
||||
|
||||
import okhttp3.internal.spdy.hpackjson.Case;
|
||||
import okhttp3.internal.spdy.hpackjson.HpackJsonUtil;
|
||||
import okhttp3.internal.spdy.hpackjson.Story;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import okhttp3.internal.spdy.hpackjson.Case;
|
||||
import okhttp3.internal.spdy.hpackjson.HpackJsonUtil;
|
||||
import okhttp3.internal.spdy.hpackjson.Story;
|
||||
import okio.Buffer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -44,7 +44,7 @@ public class HpackDecodeTestBase {
|
||||
fail("No stories for: " + interopTestName);
|
||||
}
|
||||
for (Story story : stories) {
|
||||
result.add(new Story[] { story });
|
||||
result.add(new Story[] {story});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -60,8 +60,7 @@ public class HpackDecodeTestBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects wire to be set for all cases, and compares the decoder's output to
|
||||
* expected headers.
|
||||
* Expects wire to be set for all cases, and compares the decoder's output to expected headers.
|
||||
*/
|
||||
protected void testDecoder() throws Exception {
|
||||
testDecoder(story);
|
||||
@@ -75,9 +74,10 @@ public class HpackDecodeTestBase {
|
||||
hpackReader.getAndResetHeaderList());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if {@code expected} and {@code observed} are equal when viewed as a
|
||||
* set and headers are deduped.
|
||||
* Checks if {@code expected} and {@code observed} are equal when viewed as a set and headers are
|
||||
* deduped.
|
||||
*
|
||||
* TODO: See if duped headers should be preserved on decode and verify.
|
||||
*/
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package okhttp3.internal.spdy;
|
||||
|
||||
import java.util.Collection;
|
||||
import okhttp3.internal.spdy.hpackjson.Case;
|
||||
import okhttp3.internal.spdy.hpackjson.Story;
|
||||
import okio.Buffer;
|
||||
@@ -22,8 +23,6 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Tests for round-tripping headers through hpack..
|
||||
*/
|
||||
@@ -34,9 +33,9 @@ import java.util.Collection;
|
||||
@RunWith(Parameterized.class)
|
||||
public class HpackRoundTripTest extends HpackDecodeTestBase {
|
||||
|
||||
private static final String[] RAW_DATA = { "raw-data" };
|
||||
private static final String[] RAW_DATA = {"raw-data"};
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static Collection<Story[]> getStories() throws Exception {
|
||||
return createStories(RAW_DATA);
|
||||
}
|
||||
@@ -59,5 +58,4 @@ public class HpackRoundTripTest extends HpackDecodeTestBase {
|
||||
|
||||
testDecoder(story);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,9 +23,8 @@ import okhttp3.internal.framed.Header;
|
||||
import okio.ByteString;
|
||||
|
||||
/**
|
||||
* Representation of an individual case (set of headers and wire format).
|
||||
* There are many cases for a single story. This class is used reflectively
|
||||
* with Gson to parse stories.
|
||||
* Representation of an individual case (set of headers and wire format). There are many cases for a
|
||||
* single story. This class is used reflectively with Gson to parse stories.
|
||||
*/
|
||||
public class Case implements Cloneable {
|
||||
|
||||
|
||||
@@ -85,5 +85,6 @@ public final class HpackJsonUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
private HpackJsonUtil() { } // Utilities only.
|
||||
private HpackJsonUtil() {
|
||||
} // Utilities only.
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Representation of one story, a set of request headers to encode or decode.
|
||||
* This class is used reflectively with Gson to parse stories from files.
|
||||
* Representation of one story, a set of request headers to encode or decode. This class is used
|
||||
* reflectively with Gson to parse stories from files.
|
||||
*/
|
||||
public class Story implements Cloneable {
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package okhttp3.logging;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import okhttp3.Connection;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.Interceptor;
|
||||
@@ -27,19 +30,15 @@ import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.internal.Platform;
|
||||
import okhttp3.internal.http.HttpEngine;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSource;
|
||||
|
||||
/**
|
||||
* An OkHttp interceptor which logs request and response information. Can be applied as an
|
||||
* {@linkplain OkHttpClient#interceptors() application interceptor} or as a
|
||||
* {@linkplain OkHttpClient#networkInterceptors() network interceptor}.
|
||||
* <p>
|
||||
* The format of the logs created by this class should not be considered stable and may change
|
||||
* slightly between releases. If you need a stable logging format, use your own interceptor.
|
||||
* {@linkplain OkHttpClient#interceptors() application interceptor} or as a {@linkplain
|
||||
* OkHttpClient#networkInterceptors() network interceptor}. <p> The format of the logs created by
|
||||
* this class should not be considered stable and may change slightly between releases. If you need
|
||||
* a stable logging format, use your own interceptor.
|
||||
*/
|
||||
public final class HttpLoggingInterceptor implements Interceptor {
|
||||
private static final Charset UTF8 = Charset.forName("UTF-8");
|
||||
@@ -49,8 +48,8 @@ public final class HttpLoggingInterceptor implements Interceptor {
|
||||
NONE,
|
||||
/**
|
||||
* Logs request and response lines.
|
||||
* <p>
|
||||
* Example:
|
||||
*
|
||||
* <p>Example:
|
||||
* <pre>{@code
|
||||
* --> POST /greeting HTTP/1.1 (3-byte body)
|
||||
*
|
||||
@@ -60,8 +59,8 @@ public final class HttpLoggingInterceptor implements Interceptor {
|
||||
BASIC,
|
||||
/**
|
||||
* Logs request and response lines and their respective headers.
|
||||
* <p>
|
||||
* Example:
|
||||
*
|
||||
* <p>Example:
|
||||
* <pre>{@code
|
||||
* --> POST /greeting HTTP/1.1
|
||||
* Host: example.com
|
||||
@@ -78,8 +77,8 @@ public final class HttpLoggingInterceptor implements Interceptor {
|
||||
HEADERS,
|
||||
/**
|
||||
* Logs request and response lines and their respective headers and bodies (if present).
|
||||
* <p>
|
||||
* Example:
|
||||
*
|
||||
* <p>Example:
|
||||
* <pre>{@code
|
||||
* --> POST /greeting HTTP/1.1
|
||||
* Host: example.com
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
*/
|
||||
package okhttp3.logging;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
@@ -24,10 +28,6 @@ import okhttp3.Response;
|
||||
import okhttp3.logging.HttpLoggingInterceptor.Level;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSink;
|
||||
import okio.ByteString;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
|
||||
@@ -15,18 +15,16 @@
|
||||
*/
|
||||
package okhttp3.testing;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runner.Result;
|
||||
import org.junit.runner.notification.RunListener;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
/**
|
||||
* A {@link org.junit.runner.notification.RunListener} used to install an aggressive default
|
||||
* {@link java.lang.Thread.UncaughtExceptionHandler} similar to the one found on Android.
|
||||
* No exceptions should escape from OkHttp that might cause apps to be killed or tests to fail on
|
||||
* Android.
|
||||
* A {@link org.junit.runner.notification.RunListener} used to install an aggressive default {@link
|
||||
* java.lang.Thread.UncaughtExceptionHandler} similar to the one found on Android. No exceptions
|
||||
* should escape from OkHttp that might cause apps to be killed or tests to fail on Android.
|
||||
*/
|
||||
public class InstallUncaughtExceptionHandlerListener extends RunListener {
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
package okhttp3;
|
||||
|
||||
import java.util.List;
|
||||
import javax.net.SocketFactory;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.internal.http.AuthenticatorAdapter;
|
||||
import okhttp3.internal.http.RecordingProxySelector;
|
||||
import java.util.List;
|
||||
import javax.net.SocketFactory;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -16,13 +16,6 @@
|
||||
|
||||
package okhttp3;
|
||||
|
||||
import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.internal.io.InMemoryFileSystem;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.CookieHandler;
|
||||
@@ -47,6 +40,13 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.internal.io.InMemoryFileSystem;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSink;
|
||||
import okio.BufferedSource;
|
||||
@@ -369,10 +369,9 @@ public final class CacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* We've had bugs where caching and cross-protocol redirects yield class
|
||||
* cast exceptions internal to the cache because we incorrectly assumed that
|
||||
* HttpsURLConnection was always HTTPS and HttpURLConnection was always HTTP;
|
||||
* in practice redirects mean that each can do either.
|
||||
* We've had bugs where caching and cross-protocol redirects yield class cast exceptions internal
|
||||
* to the cache because we incorrectly assumed that HttpsURLConnection was always HTTPS and
|
||||
* HttpURLConnection was always HTTP; in practice redirects mean that each can do either.
|
||||
*
|
||||
* https://github.com/square/okhttp/issues/214
|
||||
*/
|
||||
@@ -1262,8 +1261,8 @@ public final class CacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* For Last-Modified and Date headers, we should echo the date back in the
|
||||
* exact format we were served.
|
||||
* For Last-Modified and Date headers, we should echo the date back in the exact format we were
|
||||
* served.
|
||||
*/
|
||||
@Test public void retainServedDateFormat() throws Exception {
|
||||
// Serve a response with a non-standard date format that OkHttp supports.
|
||||
@@ -1877,10 +1876,9 @@ public final class CacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Old implementations of OkHttp's response cache wrote header fields like
|
||||
* ":status: 200 OK". This broke our cached response parser because it split
|
||||
* on the first colon. This regression test exists to help us read these old
|
||||
* bad cache entries.
|
||||
* Old implementations of OkHttp's response cache wrote header fields like ":status: 200 OK". This
|
||||
* broke our cached response parser because it split on the first colon. This regression test
|
||||
* exists to help us read these old bad cache entries.
|
||||
*
|
||||
* https://github.com/square/okhttp/issues/227
|
||||
*/
|
||||
@@ -2278,7 +2276,6 @@ public final class CacheTest {
|
||||
return client.newCall(request).execute();
|
||||
}
|
||||
|
||||
|
||||
private void writeFile(File directory, String file, String content) throws IOException {
|
||||
BufferedSink sink = Okio.buffer(fileSystem.sink(new File(directory, file)));
|
||||
sink.writeUtf8(content);
|
||||
@@ -2286,9 +2283,8 @@ public final class CacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param delta the offset from the current date to use. Negative
|
||||
* values yield dates in the past; positive values yield dates in the
|
||||
* future.
|
||||
* @param delta the offset from the current date to use. Negative values yield dates in the past;
|
||||
* positive values yield dates in the future.
|
||||
*/
|
||||
private String formatDate(long delta, TimeUnit timeUnit) {
|
||||
return formatDate(new Date(System.currentTimeMillis() + timeUnit.toMillis(delta)));
|
||||
@@ -2358,9 +2354,8 @@ public final class CacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortens the body of {@code response} but not the corresponding headers.
|
||||
* Only useful to test how clients respond to the premature conclusion of
|
||||
* the HTTP body.
|
||||
* Shortens the body of {@code response} but not the corresponding headers. Only useful to test
|
||||
* how clients respond to the premature conclusion of the HTTP body.
|
||||
*/
|
||||
private MockResponse truncateViolently(MockResponse response, int numBytesToKeep) {
|
||||
response.setSocketPolicy(DISCONNECT_AT_END);
|
||||
|
||||
@@ -579,14 +579,14 @@ public final class CallTest {
|
||||
try {
|
||||
call.execute();
|
||||
fail();
|
||||
} catch (IllegalStateException e){
|
||||
} catch (IllegalStateException e) {
|
||||
assertEquals("Already Executed", e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
call.enqueue(callback);
|
||||
fail();
|
||||
} catch (IllegalStateException e){
|
||||
} catch (IllegalStateException e) {
|
||||
assertEquals("Already Executed", e.getMessage());
|
||||
}
|
||||
|
||||
@@ -609,14 +609,14 @@ public final class CallTest {
|
||||
try {
|
||||
call.execute();
|
||||
fail();
|
||||
} catch (IllegalStateException e){
|
||||
} catch (IllegalStateException e) {
|
||||
assertEquals("Already Executed", e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
call.enqueue(callback);
|
||||
fail();
|
||||
} catch (IllegalStateException e){
|
||||
} catch (IllegalStateException e) {
|
||||
assertEquals("Already Executed", e.getMessage());
|
||||
}
|
||||
|
||||
@@ -822,6 +822,7 @@ public final class CallTest {
|
||||
@Override public MediaType contentType() {
|
||||
return MediaType.parse("text/plain");
|
||||
}
|
||||
|
||||
@Override public void writeTo(BufferedSink sink) throws IOException {
|
||||
sink.writeUtf8("abc");
|
||||
sink.timeout().deadline(5, TimeUnit.SECONDS);
|
||||
@@ -839,6 +840,7 @@ public final class CallTest {
|
||||
@Override public MediaType contentType() {
|
||||
return MediaType.parse("text/plain");
|
||||
}
|
||||
|
||||
@Override public void writeTo(BufferedSink sink) throws IOException {
|
||||
assertFalse(sink.timeout().hasDeadline());
|
||||
sink.writeUtf8("def");
|
||||
@@ -2246,8 +2248,8 @@ public final class CallTest {
|
||||
|
||||
/**
|
||||
* Used during tests that involve TLS connection fallback attempts. OkHttp includes the
|
||||
* TLS_FALLBACK_SCSV cipher on fallback connections. See
|
||||
* {@link FallbackTestClientSocketFactory} for details.
|
||||
* TLS_FALLBACK_SCSV cipher on fallback connections. See {@link FallbackTestClientSocketFactory}
|
||||
* for details.
|
||||
*/
|
||||
private void suppressTlsFallbackScsv(OkHttpClient client) {
|
||||
FallbackTestClientSocketFactory clientSocketFactory =
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package okhttp3;
|
||||
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.KeyPair;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Set;
|
||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okio.ByteString;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -165,7 +165,8 @@ public final class CertificatePinnerTest {
|
||||
certificatePinner.check("a.example.com", keypairACertificate1);
|
||||
}
|
||||
|
||||
@Test public void successfulMatchAcceptsAnyMatchingCertificateForWildcardHostname() throws Exception {
|
||||
@Test public void successfulMatchAcceptsAnyMatchingCertificateForWildcardHostname()
|
||||
throws Exception {
|
||||
CertificatePinner certificatePinner = new CertificatePinner.Builder()
|
||||
.add("*.example.com", keypairBCertificate1Pin)
|
||||
.build();
|
||||
@@ -194,7 +195,8 @@ public final class CertificatePinnerTest {
|
||||
certificatePinner.check("a.example.com", keypairBCertificate1);
|
||||
}
|
||||
|
||||
@Test public void successfulCheckForOneHostnameWithWildcardAndDirectCertificate() throws Exception {
|
||||
@Test public void successfulCheckForOneHostnameWithWildcardAndDirectCertificate()
|
||||
throws Exception {
|
||||
CertificatePinner certificatePinner = new CertificatePinner.Builder()
|
||||
.add("*.example.com", keypairACertificate1Pin)
|
||||
.add("a.example.com", keypairBCertificate1Pin)
|
||||
@@ -204,7 +206,8 @@ public final class CertificatePinnerTest {
|
||||
certificatePinner.check("a.example.com", keypairBCertificate1);
|
||||
}
|
||||
|
||||
@Test public void unsuccessfulCheckForOneHostnameWithWildcardAndDirectCertificate() throws Exception {
|
||||
@Test public void unsuccessfulCheckForOneHostnameWithWildcardAndDirectCertificate()
|
||||
throws Exception {
|
||||
CertificatePinner certificatePinner = new CertificatePinner.Builder()
|
||||
.add("*.example.com", keypairACertificate1Pin)
|
||||
.add("a.example.com", keypairBCertificate1Pin)
|
||||
@@ -223,7 +226,8 @@ public final class CertificatePinnerTest {
|
||||
.add("second.com", keypairCCertificate1Pin)
|
||||
.build();
|
||||
|
||||
Set<ByteString> expectedPins = setOf(keypairACertificate1PinBase64, keypairBCertificate1PinBase64);
|
||||
Set<ByteString> expectedPins =
|
||||
setOf(keypairACertificate1PinBase64, keypairBCertificate1PinBase64);
|
||||
Set<ByteString> matchedPins = certificatePinner.findMatchingPins("first.com");
|
||||
|
||||
assertEquals(expectedPins, matchedPins);
|
||||
@@ -236,7 +240,8 @@ public final class CertificatePinnerTest {
|
||||
.add("b.example.com", keypairCCertificate1Pin)
|
||||
.build();
|
||||
|
||||
Set<ByteString> expectedPins = setOf(keypairACertificate1PinBase64, keypairBCertificate1PinBase64);
|
||||
Set<ByteString> expectedPins =
|
||||
setOf(keypairACertificate1PinBase64, keypairBCertificate1PinBase64);
|
||||
Set<ByteString> matchedPins = certificatePinner.findMatchingPins("a.example.com");
|
||||
|
||||
assertEquals(expectedPins, matchedPins);
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package okhttp3;
|
||||
|
||||
import okhttp3.internal.RecordingOkAuthenticator;
|
||||
import okhttp3.internal.http.StreamAllocation;
|
||||
import okhttp3.internal.io.RealConnection;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.ProxySelector;
|
||||
@@ -25,6 +22,9 @@ import java.net.Socket;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.net.SocketFactory;
|
||||
import okhttp3.internal.RecordingOkAuthenticator;
|
||||
import okhttp3.internal.http.StreamAllocation;
|
||||
import okhttp3.internal.io.RealConnection;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
*/
|
||||
package okhttp3;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.SocketPolicy;
|
||||
import okhttp3.testing.RecordingHostnameVerifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestRule;
|
||||
|
||||
@@ -249,10 +249,10 @@ public final class ConnectionSpecTest {
|
||||
});
|
||||
|
||||
socket.setEnabledProtocols(
|
||||
new String[] { TlsVersion.TLS_1_2.javaName, TlsVersion.TLS_1_1.javaName });
|
||||
new String[] {TlsVersion.TLS_1_2.javaName, TlsVersion.TLS_1_1.javaName});
|
||||
assertTrue(tlsSpec.isCompatible(socket));
|
||||
|
||||
socket.setEnabledProtocols(new String[] { TlsVersion.TLS_1_1.javaName });
|
||||
socket.setEnabledProtocols(new String[] {TlsVersion.TLS_1_1.javaName});
|
||||
assertFalse(tlsSpec.isCompatible(socket));
|
||||
}
|
||||
|
||||
|
||||
@@ -19,13 +19,12 @@ import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import javax.net.SocketFactory;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
/**
|
||||
* A {@link SSLSocketFactory} that delegates calls. Sockets can be configured after
|
||||
* creation by overriding {@link #configureSocket(javax.net.ssl.SSLSocket)}.
|
||||
* A {@link SSLSocketFactory} that delegates calls. Sockets can be configured after creation by
|
||||
* overriding {@link #configureSocket(javax.net.ssl.SSLSocket)}.
|
||||
*/
|
||||
public class DelegatingSSLSocketFactory extends SSLSocketFactory {
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ import javax.net.ssl.SSLSocketFactory;
|
||||
*/
|
||||
public class FallbackTestClientSocketFactory extends DelegatingSSLSocketFactory {
|
||||
/**
|
||||
* The cipher suite used during TLS connection fallback to indicate a fallback.
|
||||
* See https://tools.ietf.org/html/draft-ietf-tls-downgrade-scsv-00
|
||||
* The cipher suite used during TLS connection fallback to indicate a fallback. See
|
||||
* https://tools.ietf.org/html/draft-ietf-tls-downgrade-scsv-00
|
||||
*/
|
||||
public static final String TLS_FALLBACK_SCSV = "TLS_FALLBACK_SCSV";
|
||||
|
||||
|
||||
@@ -189,7 +189,7 @@ public final class FormBodyTest {
|
||||
private String formEncode(int codePoint) throws IOException {
|
||||
// Wrap the codepoint with regular printable characters to prevent trimming.
|
||||
FormBody body = new FormBody.Builder()
|
||||
.add("a", new String(new int[] { 'b', codePoint, 'c' }, 0, 3))
|
||||
.add("a", new String(new int[] {'b', codePoint, 'c'}, 0, 3))
|
||||
.build();
|
||||
Buffer buffer = new Buffer();
|
||||
body.writeTo(buffer);
|
||||
|
||||
@@ -1307,8 +1307,8 @@ public final class HttpUrlTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Although HttpUrl prefers percent-encodings in uppercase, it should preserve the exact
|
||||
* structure of the original encoding.
|
||||
* Although HttpUrl prefers percent-encodings in uppercase, it should preserve the exact structure
|
||||
* of the original encoding.
|
||||
*/
|
||||
@Test public void rawEncodingRetained() throws Exception {
|
||||
String urlString = "http://%6d%6D:%6d%6D@host/%6d%6D?%6d%6D#%6d%6D";
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package okhttp3;
|
||||
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -27,6 +24,9 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSink;
|
||||
import okio.ForwardingSink;
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
*/
|
||||
package okhttp3;
|
||||
|
||||
import okhttp3.internal.Util;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.IllegalCharsetNameException;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
import okhttp3.internal.Util;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -30,8 +30,8 @@ import static org.junit.Assert.fail;
|
||||
/**
|
||||
* Test MediaType API and parsing.
|
||||
*
|
||||
* <p>This test includes tests from <a
|
||||
* href="https://code.google.com/p/guava-libraries/">Guava's</a> MediaTypeTest.
|
||||
* <p>This test includes tests from <a href="https://code.google.com/p/guava-libraries/">Guava's</a>
|
||||
* MediaTypeTest.
|
||||
*/
|
||||
public class MediaTypeTest {
|
||||
@Test public void testParse() throws Exception {
|
||||
|
||||
@@ -106,8 +106,7 @@ public final class OkHttpClientTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm that {@code copyWithDefaults} gets some default implementations
|
||||
* from the core library.
|
||||
* Confirm that {@code copyWithDefaults} gets some default implementations from the core library.
|
||||
*/
|
||||
@Test public void copyWithDefaultsWhenDefaultIsGlobal() throws Exception {
|
||||
ProxySelector proxySelector = new RecordingProxySelector();
|
||||
@@ -164,8 +163,8 @@ public final class OkHttpClientTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* When copying the client, stateful things like the connection pool are
|
||||
* shared across all clients.
|
||||
* When copying the client, stateful things like the connection pool are shared across all
|
||||
* clients.
|
||||
*/
|
||||
@Test public void cloneSharesStatefulInstances() throws Exception {
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
package okhttp3;
|
||||
|
||||
import okhttp3.ws.WebSocket;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import okhttp3.ws.WebSocket;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -96,8 +96,7 @@ public final class RecordedResponse {
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the current response was redirected and returns the prior
|
||||
* response.
|
||||
* Asserts that the current response was redirected and returns the prior response.
|
||||
*/
|
||||
public RecordedResponse priorResponse() {
|
||||
Response priorResponse = response.priorResponse();
|
||||
@@ -107,8 +106,7 @@ public final class RecordedResponse {
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the current response used the network and returns the network
|
||||
* response.
|
||||
* Asserts that the current response used the network and returns the network response.
|
||||
*/
|
||||
public RecordedResponse networkResponse() {
|
||||
Response networkResponse = response.networkResponse();
|
||||
@@ -130,8 +128,7 @@ public final class RecordedResponse {
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the current response used the cache and returns the cache
|
||||
* response.
|
||||
* Asserts that the current response used the cache and returns the cache response.
|
||||
*/
|
||||
public RecordedResponse cacheResponse() {
|
||||
Response cacheResponse = response.cacheResponse();
|
||||
|
||||
@@ -41,8 +41,8 @@ public class RecordingCallback implements Callback {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the recorded response triggered by {@code request}. Throws if the
|
||||
* response isn't enqueued before the timeout.
|
||||
* Returns the recorded response triggered by {@code request}. Throws if the response isn't
|
||||
* enqueued before the timeout.
|
||||
*/
|
||||
public synchronized RecordedResponse await(HttpUrl url) throws Exception {
|
||||
long timeoutMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) + TIMEOUT_MILLIS;
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package okhttp3;
|
||||
|
||||
import okhttp3.internal.Util;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import okhttp3.internal.Util;
|
||||
import okio.Buffer;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -125,7 +125,8 @@ public final class RequestTest {
|
||||
|
||||
@Test public void newBuilderUrlResetsUrl() throws Exception {
|
||||
Request requestWithoutCache = new Request.Builder().url("http://localhost/api").build();
|
||||
Request builtRequestWithoutCache = requestWithoutCache.newBuilder().url("http://localhost/api/foo").build();
|
||||
Request builtRequestWithoutCache =
|
||||
requestWithoutCache.newBuilder().url("http://localhost/api/foo").build();
|
||||
assertEquals(HttpUrl.parse("http://localhost/api/foo"), builtRequestWithoutCache.url());
|
||||
|
||||
Request requestWithCache = new Request.Builder().url("http://localhost/api").build();
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package okhttp3;
|
||||
|
||||
import okhttp3.internal.NamedRunnable;
|
||||
import okhttp3.internal.Util;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -31,6 +29,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import okhttp3.internal.NamedRunnable;
|
||||
import okhttp3.internal.Util;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSink;
|
||||
import okio.BufferedSource;
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package okhttp3;
|
||||
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import java.io.IOException;
|
||||
import java.net.Proxy;
|
||||
import java.net.ProxySelector;
|
||||
@@ -24,6 +22,8 @@ import java.net.SocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package okhttp3;
|
||||
|
||||
import okhttp3.internal.framed.Header;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import okhttp3.internal.framed.Header;
|
||||
|
||||
public final class TestUtil {
|
||||
private TestUtil() {
|
||||
|
||||
@@ -16,18 +16,6 @@
|
||||
|
||||
package okhttp3;
|
||||
|
||||
import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.RecordingAuthenticator;
|
||||
import okhttp3.internal.RecordingOkAuthenticator;
|
||||
import okhttp3.internal.SingleInetAddressDns;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.internal.Version;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import okhttp3.mockwebserver.SocketPolicy;
|
||||
import okhttp3.testing.RecordingHostnameVerifier;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -69,6 +57,18 @@ import javax.net.ssl.SSLHandshakeException;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.RecordingAuthenticator;
|
||||
import okhttp3.internal.RecordingOkAuthenticator;
|
||||
import okhttp3.internal.SingleInetAddressDns;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.internal.Version;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import okhttp3.mockwebserver.SocketPolicy;
|
||||
import okhttp3.testing.RecordingHostnameVerifier;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSink;
|
||||
import okio.GzipSink;
|
||||
@@ -636,8 +636,8 @@ public final class URLConnectionTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* When a pooled connection fails, don't blame the route. Otherwise pooled
|
||||
* connection failures can cause unnecessary SSL fallbacks.
|
||||
* When a pooled connection fails, don't blame the route. Otherwise pooled connection failures can
|
||||
* cause unnecessary SSL fallbacks.
|
||||
*
|
||||
* https://github.com/square/okhttp/issues/515
|
||||
*/
|
||||
@@ -733,11 +733,23 @@ public final class URLConnectionTest {
|
||||
|
||||
public void testConnectViaSocketFactory(boolean useHttps) throws IOException {
|
||||
SocketFactory uselessSocketFactory = new SocketFactory() {
|
||||
public Socket createSocket() { throw new IllegalArgumentException("useless"); }
|
||||
public Socket createSocket(InetAddress host, int port) { return null; }
|
||||
public Socket createSocket() {
|
||||
throw new IllegalArgumentException("useless");
|
||||
}
|
||||
|
||||
public Socket createSocket(InetAddress host, int port) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Socket createSocket(InetAddress address, int port, InetAddress localAddress,
|
||||
int localPort) { return null; }
|
||||
public Socket createSocket(String host, int port) { return null; }
|
||||
int localPort) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Socket createSocket(String host, int port) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) {
|
||||
return null;
|
||||
}
|
||||
@@ -837,8 +849,8 @@ public final class URLConnectionTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* We weren't honoring all of the appropriate proxy system properties when
|
||||
* connecting via HTTPS. http://b/3097518
|
||||
* We weren't honoring all of the appropriate proxy system properties when connecting via HTTPS.
|
||||
* http://b/3097518
|
||||
*/
|
||||
@Test public void connectViaHttpProxyToHttpsUsingProxySystemProperty() throws Exception {
|
||||
testConnectViaHttpProxyToHttps(ProxyConfig.PROXY_SYSTEM_PROPERTY);
|
||||
@@ -849,8 +861,8 @@ public final class URLConnectionTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* We were verifying the wrong hostname when connecting to an HTTPS site
|
||||
* through a proxy. http://b/3097277
|
||||
* We were verifying the wrong hostname when connecting to an HTTPS site through a proxy.
|
||||
* http://b/3097277
|
||||
*/
|
||||
private void testConnectViaHttpProxyToHttps(ProxyConfig proxyConfig) throws Exception {
|
||||
RecordingHostnameVerifier hostnameVerifier = new RecordingHostnameVerifier();
|
||||
@@ -1050,9 +1062,8 @@ public final class URLConnectionTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads {@code count} characters from the stream. If the stream is
|
||||
* exhausted before {@code count} characters can be read, the remaining
|
||||
* characters are returned and the stream is closed.
|
||||
* Reads {@code count} characters from the stream. If the stream is exhausted before {@code count}
|
||||
* characters can be read, the remaining characters are returned and the stream is closed.
|
||||
*/
|
||||
private String readAscii(InputStream in, int count) throws IOException {
|
||||
StringBuilder result = new StringBuilder();
|
||||
@@ -1100,9 +1111,8 @@ public final class URLConnectionTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* We've had a bug where we forget the HTTP response when we see response
|
||||
* code 401. This causes a new HTTP request to be issued for every call into
|
||||
* the URLConnection.
|
||||
* We've had a bug where we forget the HTTP response when we see response code 401. This causes a
|
||||
* new HTTP request to be issued for every call into the URLConnection.
|
||||
*/
|
||||
@Test public void unauthorizedResponseHandling() throws IOException {
|
||||
MockResponse response = new MockResponse().addHeader("WWW-Authenticate: challenge")
|
||||
@@ -1177,9 +1187,8 @@ public final class URLConnectionTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* This test checks whether connections are gzipped by default. This
|
||||
* behavior in not required by the API, so a failure of this test does not
|
||||
* imply a bug in the implementation.
|
||||
* This test checks whether connections are gzipped by default. This behavior in not required by
|
||||
* the API, so a failure of this test does not imply a bug in the implementation.
|
||||
*/
|
||||
@Test public void gzipEncodingEnabledByDefault() throws IOException, InterruptedException {
|
||||
server.enqueue(new MockResponse()
|
||||
@@ -1239,9 +1248,8 @@ public final class URLConnectionTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a bug where gzip input streams weren't exhausting the input stream,
|
||||
* which corrupted the request that followed or prevented connection reuse.
|
||||
* http://code.google.com/p/android/issues/detail?id=7059
|
||||
* Test a bug where gzip input streams weren't exhausting the input stream, which corrupted the
|
||||
* request that followed or prevented connection reuse. http://code.google.com/p/android/issues/detail?id=7059
|
||||
* http://code.google.com/p/android/issues/detail?id=38817
|
||||
*/
|
||||
private void testClientConfiguredGzipContentEncodingAndConnectionReuse(TransferKind transferKind,
|
||||
@@ -1402,7 +1410,7 @@ public final class URLConnectionTest {
|
||||
Authenticator.setDefault(new RecordingAuthenticator());
|
||||
connection = client.open(server.url("/").url());
|
||||
connection.setDoOutput(true);
|
||||
byte[] requestBody = { 'A', 'B', 'C', 'D' };
|
||||
byte[] requestBody = {'A', 'B', 'C', 'D'};
|
||||
if (streamingMode == StreamingMode.FIXED_LENGTH) {
|
||||
connection.setFixedLengthStreamingMode(requestBody.length);
|
||||
} else if (streamingMode == StreamingMode.CHUNKED) {
|
||||
@@ -1684,7 +1692,7 @@ public final class URLConnectionTest {
|
||||
client.client().setHostnameVerifier(new RecordingHostnameVerifier());
|
||||
connection = client.open(server.url("/").url());
|
||||
connection.setDoOutput(true);
|
||||
byte[] requestBody = { 'A', 'B', 'C', 'D' };
|
||||
byte[] requestBody = {'A', 'B', 'C', 'D'};
|
||||
if (streamingMode == StreamingMode.FIXED_LENGTH) {
|
||||
connection.setFixedLengthStreamingMode(requestBody.length);
|
||||
} else if (streamingMode == StreamingMode.CHUNKED) {
|
||||
@@ -1723,7 +1731,7 @@ public final class URLConnectionTest {
|
||||
Authenticator.setDefault(new RecordingAuthenticator());
|
||||
connection = client.open(server.url("/").url());
|
||||
connection.setDoOutput(true);
|
||||
byte[] requestBody = { 'A', 'B', 'C', 'D' };
|
||||
byte[] requestBody = {'A', 'B', 'C', 'D'};
|
||||
OutputStream outputStream = connection.getOutputStream();
|
||||
outputStream.write(requestBody);
|
||||
outputStream.close();
|
||||
@@ -2046,7 +2054,7 @@ public final class URLConnectionTest {
|
||||
connection = client.open(server.url("/page1").url());
|
||||
connection.setDoOutput(true);
|
||||
transferKind.setForRequest(connection, 4);
|
||||
byte[] requestBody = { 'A', 'B', 'C', 'D' };
|
||||
byte[] requestBody = {'A', 'B', 'C', 'D'};
|
||||
OutputStream outputStream = connection.getOutputStream();
|
||||
outputStream.write(requestBody);
|
||||
outputStream.close();
|
||||
@@ -2144,7 +2152,7 @@ public final class URLConnectionTest {
|
||||
|
||||
connection = client.open(server.url("/page1").url());
|
||||
connection.setRequestMethod(method);
|
||||
byte[] requestBody = { 'A', 'B', 'C', 'D' };
|
||||
byte[] requestBody = {'A', 'B', 'C', 'D'};
|
||||
if (method.equals("POST")) {
|
||||
connection.setDoOutput(true);
|
||||
OutputStream outputStream = connection.getOutputStream();
|
||||
@@ -2215,7 +2223,7 @@ public final class URLConnectionTest {
|
||||
RecordingHostnameVerifier hostnameVerifier = new RecordingHostnameVerifier();
|
||||
RecordingTrustManager trustManager = new RecordingTrustManager();
|
||||
SSLContext sc = SSLContext.getInstance("TLS");
|
||||
sc.init(null, new TrustManager[] { trustManager }, new java.security.SecureRandom());
|
||||
sc.init(null, new TrustManager[] {trustManager}, new java.security.SecureRandom());
|
||||
|
||||
client.client().setHostnameVerifier(hostnameVerifier);
|
||||
client.client().setSslSocketFactory(sc.getSocketFactory());
|
||||
@@ -2362,8 +2370,7 @@ public final class URLConnectionTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retry redirects if the socket is closed.
|
||||
* https://code.google.com/p/android/issues/detail?id=41576
|
||||
* Retry redirects if the socket is closed. https://code.google.com/p/android/issues/detail?id=41576
|
||||
*/
|
||||
@Test public void sameConnectionRedirectAndReuse() throws Exception {
|
||||
server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_MOVED_TEMP)
|
||||
@@ -2409,9 +2416,9 @@ public final class URLConnectionTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* We explicitly permit apps to close the upload stream even after it has
|
||||
* been transmitted. We also permit flush so that buffered streams can
|
||||
* do a no-op flush when they are closed. http://b/3038470
|
||||
* We explicitly permit apps to close the upload stream even after it has been transmitted. We
|
||||
* also permit flush so that buffered streams can do a no-op flush when they are closed.
|
||||
* http://b/3038470
|
||||
*/
|
||||
private void testFlushAfterStreamTransmitted(TransferKind transferKind) throws IOException {
|
||||
server.enqueue(new MockResponse().setBody("abc"));
|
||||
@@ -2521,11 +2528,11 @@ public final class URLConnectionTest {
|
||||
} catch (NullPointerException expected) {
|
||||
}
|
||||
try {
|
||||
connection.getContent(new Class[] { null });
|
||||
connection.getContent(new Class[] {null});
|
||||
fail();
|
||||
} catch (NullPointerException expected) {
|
||||
}
|
||||
assertNull(connection.getContent(new Class[] { getClass() }));
|
||||
assertNull(connection.getContent(new Class[] {getClass()}));
|
||||
connection.getInputStream().close();
|
||||
}
|
||||
|
||||
@@ -2574,7 +2581,7 @@ public final class URLConnectionTest {
|
||||
connection = client.open(server.url("/").url());
|
||||
connection.setDoOutput(true);
|
||||
OutputStream out = connection.getOutputStream();
|
||||
out.write(new byte[] { 'A', 'B', 'C' });
|
||||
out.write(new byte[] {'A', 'B', 'C'});
|
||||
out.close();
|
||||
assertEquals("A", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
|
||||
RecordedRequest request = server.takeRequest();
|
||||
@@ -3120,10 +3127,9 @@ public final class URLConnectionTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* We had a bug where we attempted to gunzip responses that didn't have a
|
||||
* body. This only came up with 304s since that response code can include
|
||||
* headers (like "Content-Encoding") without any content to go along with it.
|
||||
* https://github.com/square/okhttp/issues/358
|
||||
* We had a bug where we attempted to gunzip responses that didn't have a body. This only came up
|
||||
* with 304s since that response code can include headers (like "Content-Encoding") without any
|
||||
* content to go along with it. https://github.com/square/okhttp/issues/358
|
||||
*/
|
||||
@Test public void noTransparentGzipFor304NotModified() throws Exception {
|
||||
server.enqueue(new MockResponse()
|
||||
@@ -3170,8 +3176,8 @@ public final class URLConnectionTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* The RFC is unclear in this regard as it only specifies that this should
|
||||
* invalidate the cache entry (if any).
|
||||
* The RFC is unclear in this regard as it only specifies that this should invalidate the cache
|
||||
* entry (if any).
|
||||
*/
|
||||
@Test public void bodyPermittedOnDelete() throws Exception {
|
||||
server.enqueue(new MockResponse());
|
||||
@@ -3304,8 +3310,8 @@ public final class URLConnectionTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads at most {@code limit} characters from {@code in} and asserts that
|
||||
* content equals {@code expected}.
|
||||
* Reads at most {@code limit} characters from {@code in} and asserts that content equals {@code
|
||||
* expected}.
|
||||
*/
|
||||
private void assertContent(String expected, HttpURLConnection connection, int limit)
|
||||
throws IOException {
|
||||
@@ -3327,6 +3333,7 @@ public final class URLConnectionTest {
|
||||
throws IOException {
|
||||
response.setChunkedBody(content, chunkSize);
|
||||
}
|
||||
|
||||
@Override void setForRequest(HttpURLConnection connection, int contentLength) {
|
||||
connection.setChunkedStreamingMode(5);
|
||||
}
|
||||
@@ -3335,6 +3342,7 @@ public final class URLConnectionTest {
|
||||
@Override void setBody(MockResponse response, Buffer content, int chunkSize) {
|
||||
response.setBody(content);
|
||||
}
|
||||
|
||||
@Override void setForRequest(HttpURLConnection connection, int contentLength) {
|
||||
connection.setFixedLengthStreamingMode(contentLength);
|
||||
}
|
||||
@@ -3345,6 +3353,7 @@ public final class URLConnectionTest {
|
||||
response.setSocketPolicy(DISCONNECT_AT_END);
|
||||
response.removeHeader("Content-Length");
|
||||
}
|
||||
|
||||
@Override void setForRequest(HttpURLConnection connection, int contentLength) {
|
||||
}
|
||||
};
|
||||
@@ -3416,7 +3425,7 @@ public final class URLConnectionTest {
|
||||
private final List<String> calls = new ArrayList<String>();
|
||||
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return new X509Certificate[] { };
|
||||
return new X509Certificate[] {};
|
||||
}
|
||||
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType)
|
||||
@@ -3466,8 +3475,8 @@ public final class URLConnectionTest {
|
||||
|
||||
/**
|
||||
* Used during tests that involve TLS connection fallback attempts. OkHttp includes the
|
||||
* TLS_FALLBACK_SCSV cipher on fallback connections. See
|
||||
* {@link FallbackTestClientSocketFactory} for details.
|
||||
* TLS_FALLBACK_SCSV cipher on fallback connections. See {@link FallbackTestClientSocketFactory}
|
||||
* for details.
|
||||
*/
|
||||
private void suppressTlsFallbackScsv(OkHttpClient client) {
|
||||
FallbackTestClientSocketFactory clientSocketFactory =
|
||||
|
||||
@@ -38,6 +38,7 @@ class UrlComponentEncodingTester {
|
||||
* See https://url.spec.whatwg.org/#percent-encoded-bytes
|
||||
*/
|
||||
private static final Map<Integer, Encoding> defaultEncodings;
|
||||
|
||||
static {
|
||||
Map<Integer, Encoding> map = new LinkedHashMap<>();
|
||||
map.put( 0x0, Encoding.PERCENT); // Null character
|
||||
@@ -278,7 +279,7 @@ class UrlComponentEncodingTester {
|
||||
|
||||
private void testUri(
|
||||
int codePoint, Encoding encoding, Component component, boolean uriEscaped) {
|
||||
String string = new String(new int[] { codePoint }, 0, 1);
|
||||
String string = new String(new int[] {codePoint}, 0, 1);
|
||||
String encoded = encoding.encode(codePoint);
|
||||
HttpUrl httpUrl = HttpUrl.parse(component.urlString(encoded));
|
||||
URI uri = httpUrl.uri();
|
||||
@@ -305,7 +306,7 @@ class UrlComponentEncodingTester {
|
||||
public enum Encoding {
|
||||
IDENTITY {
|
||||
public String encode(int codePoint) {
|
||||
return new String(new int[] { codePoint }, 0, 1);
|
||||
return new String(new int[] {codePoint}, 0, 1);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -332,12 +333,15 @@ class UrlComponentEncodingTester {
|
||||
@Override public String urlString(String value) {
|
||||
return "http://" + value + "@example.com/";
|
||||
}
|
||||
|
||||
@Override public String encodedValue(HttpUrl url) {
|
||||
return url.encodedUsername();
|
||||
}
|
||||
|
||||
@Override public void set(HttpUrl.Builder builder, String value) {
|
||||
builder.username(value);
|
||||
}
|
||||
|
||||
@Override public String get(HttpUrl url) {
|
||||
return url.username();
|
||||
}
|
||||
@@ -346,12 +350,15 @@ class UrlComponentEncodingTester {
|
||||
@Override public String urlString(String value) {
|
||||
return "http://:" + value + "@example.com/";
|
||||
}
|
||||
|
||||
@Override public String encodedValue(HttpUrl url) {
|
||||
return url.encodedPassword();
|
||||
}
|
||||
|
||||
@Override public void set(HttpUrl.Builder builder, String value) {
|
||||
builder.password(value);
|
||||
}
|
||||
|
||||
@Override public String get(HttpUrl url) {
|
||||
return url.password();
|
||||
}
|
||||
@@ -360,13 +367,16 @@ class UrlComponentEncodingTester {
|
||||
@Override public String urlString(String value) {
|
||||
return "http://example.com/a" + value + "z/";
|
||||
}
|
||||
|
||||
@Override public String encodedValue(HttpUrl url) {
|
||||
String path = url.encodedPath();
|
||||
return path.substring(2, path.length() - 2);
|
||||
}
|
||||
|
||||
@Override public void set(HttpUrl.Builder builder, String value) {
|
||||
builder.addPathSegment("a" + value + "z");
|
||||
}
|
||||
|
||||
@Override public String get(HttpUrl url) {
|
||||
String pathSegment = url.pathSegments().get(0);
|
||||
return pathSegment.substring(1, pathSegment.length() - 1);
|
||||
@@ -376,13 +386,16 @@ class UrlComponentEncodingTester {
|
||||
@Override public String urlString(String value) {
|
||||
return "http://example.com/?a" + value + "z";
|
||||
}
|
||||
|
||||
@Override public String encodedValue(HttpUrl url) {
|
||||
String query = url.encodedQuery();
|
||||
return query.substring(1, query.length() - 1);
|
||||
}
|
||||
|
||||
@Override public void set(HttpUrl.Builder builder, String value) {
|
||||
builder.query("a" + value + "z");
|
||||
}
|
||||
|
||||
@Override public String get(HttpUrl url) {
|
||||
String query = url.query();
|
||||
return query.substring(1, query.length() - 1);
|
||||
@@ -392,13 +405,16 @@ class UrlComponentEncodingTester {
|
||||
@Override public String urlString(String value) {
|
||||
return "http://example.com/#a" + value + "z";
|
||||
}
|
||||
|
||||
@Override public String encodedValue(HttpUrl url) {
|
||||
String fragment = url.encodedFragment();
|
||||
return fragment.substring(1, fragment.length() - 1);
|
||||
}
|
||||
|
||||
@Override public void set(HttpUrl.Builder builder, String value) {
|
||||
builder.fragment("a" + value + "z");
|
||||
}
|
||||
|
||||
@Override public String get(HttpUrl url) {
|
||||
String fragment = url.fragment();
|
||||
return fragment.substring(1, fragment.length() - 1);
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
*/
|
||||
package okhttp3;
|
||||
|
||||
import okhttp3.internal.Util;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import okhttp3.internal.Util;
|
||||
import okio.BufferedSource;
|
||||
import okio.Okio;
|
||||
import org.junit.Test;
|
||||
@@ -38,7 +38,7 @@ public final class WebPlatformUrlTest {
|
||||
try {
|
||||
List<Object[]> result = new ArrayList<>();
|
||||
for (WebPlatformUrlTestData urlTestData : loadTests()) {
|
||||
result.add(new Object[] { urlTestData });
|
||||
result.add(new Object[] {urlTestData});
|
||||
}
|
||||
return result;
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package okhttp3.internal;
|
||||
|
||||
import okhttp3.ConnectionSpec;
|
||||
import okhttp3.TlsVersion;
|
||||
import java.io.IOException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.util.Arrays;
|
||||
@@ -25,6 +23,8 @@ import java.util.Set;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLHandshakeException;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import okhttp3.ConnectionSpec;
|
||||
import okhttp3.TlsVersion;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -91,7 +91,7 @@ public class ConnectionSpecSelectorTest {
|
||||
ConnectionSpecSelector connectionSpecSelector = createConnectionSpecSelector(
|
||||
ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS, sslV3);
|
||||
|
||||
TlsVersion[] enabledSocketTlsVersions = { TlsVersion.TLS_1_1, TlsVersion.TLS_1_0 };
|
||||
TlsVersion[] enabledSocketTlsVersions = {TlsVersion.TLS_1_1, TlsVersion.TLS_1_0};
|
||||
SSLSocket socket = createSocketWithEnabledProtocols(enabledSocketTlsVersions);
|
||||
|
||||
// MODERN_TLS is used here.
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package okhttp3.internal;
|
||||
|
||||
import okhttp3.internal.io.FileSystem;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayDeque;
|
||||
@@ -26,6 +25,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.Executor;
|
||||
import okhttp3.internal.io.FileSystem;
|
||||
import okio.BufferedSink;
|
||||
import okio.BufferedSource;
|
||||
import okio.Okio;
|
||||
@@ -282,8 +282,8 @@ public final class DiskLruCacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Each read sees a snapshot of the file at the time read was called.
|
||||
* This means that two reads of the same key can see different data.
|
||||
* Each read sees a snapshot of the file at the time read was called. This means that two reads of
|
||||
* the same key can see different data.
|
||||
*/
|
||||
@Test public void readAndWriteOverlapsMaintainConsistency() throws Exception {
|
||||
DiskLruCache.Editor v1Creator = cache.edit("k1");
|
||||
@@ -859,9 +859,8 @@ public final class DiskLruCacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* We had a long-lived bug where {@link DiskLruCache#trimToSize} could
|
||||
* infinite loop if entries being edited required deletion for the operation
|
||||
* to complete.
|
||||
* We had a long-lived bug where {@link DiskLruCache#trimToSize} could infinite loop if entries
|
||||
* being edited required deletion for the operation to complete.
|
||||
*/
|
||||
@Test public void trimToSizeWithActiveEdit() throws Exception {
|
||||
set("a", "a1234", "a1234");
|
||||
@@ -1275,7 +1274,8 @@ public final class DiskLruCacheTest {
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public static void setString(DiskLruCache.Editor editor, int index, String value) throws IOException {
|
||||
public static void setString(DiskLruCache.Editor editor, int index, String value)
|
||||
throws IOException {
|
||||
BufferedSink writer = Okio.buffer(editor.newSink(index));
|
||||
writer.writeUtf8(value);
|
||||
writer.close();
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
package okhttp3.internal;
|
||||
|
||||
import okhttp3.Dns;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import okhttp3.Dns;
|
||||
|
||||
/**
|
||||
* A network that always resolves two IP addresses per host. Use this when testing route selection
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package okhttp3.internal;
|
||||
|
||||
import okhttp3.internal.io.FileSystem;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import okhttp3.internal.io.FileSystem;
|
||||
import okio.Buffer;
|
||||
import okio.ForwardingSink;
|
||||
import okio.Sink;
|
||||
|
||||
@@ -17,10 +17,9 @@
|
||||
|
||||
package okhttp3.internal;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -38,7 +37,8 @@ public class OptionalMethodTest {
|
||||
return "string";
|
||||
}
|
||||
|
||||
public void voidMethod() {}
|
||||
public void voidMethod() {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@@ -70,7 +70,8 @@ public class OptionalMethodTest {
|
||||
throw new NumberFormatException();
|
||||
}
|
||||
|
||||
protected void nonPublic() {}
|
||||
protected void nonPublic() {
|
||||
}
|
||||
}
|
||||
|
||||
private final static OptionalMethod<BaseClass> STRING_METHOD_RETURNS_ANY =
|
||||
@@ -194,8 +195,10 @@ public class OptionalMethodTest {
|
||||
assertIllegalArgumentExceptionOnInvoke(METHOD_WITH_ARGS_CORRECT_PARAMS, subClass1); // no args
|
||||
assertIllegalArgumentExceptionOnInvoke(METHOD_WITH_ARGS_CORRECT_PARAMS, subClass1, 123);
|
||||
assertIllegalArgumentExceptionOnInvoke(METHOD_WITH_ARGS_CORRECT_PARAMS, subClass1, true);
|
||||
assertIllegalArgumentExceptionOnInvoke(METHOD_WITH_ARGS_CORRECT_PARAMS, subClass1, new Object());
|
||||
assertIllegalArgumentExceptionOnInvoke(METHOD_WITH_ARGS_CORRECT_PARAMS, subClass1, "one", "two");
|
||||
assertIllegalArgumentExceptionOnInvoke(METHOD_WITH_ARGS_CORRECT_PARAMS, subClass1,
|
||||
new Object());
|
||||
assertIllegalArgumentExceptionOnInvoke(METHOD_WITH_ARGS_CORRECT_PARAMS, subClass1, "one",
|
||||
"two");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -268,11 +271,15 @@ public class OptionalMethodTest {
|
||||
@Test
|
||||
public void invokeOptionalBadArgs() throws Exception {
|
||||
SubClass1 subClass1 = new SubClass1();
|
||||
assertIllegalArgumentExceptionOnInvokeOptional(METHOD_WITH_ARGS_CORRECT_PARAMS, subClass1); // no args
|
||||
assertIllegalArgumentExceptionOnInvokeOptional(METHOD_WITH_ARGS_CORRECT_PARAMS,
|
||||
subClass1); // no args
|
||||
assertIllegalArgumentExceptionOnInvokeOptional(METHOD_WITH_ARGS_CORRECT_PARAMS, subClass1, 123);
|
||||
assertIllegalArgumentExceptionOnInvokeOptional(METHOD_WITH_ARGS_CORRECT_PARAMS, subClass1, true);
|
||||
assertIllegalArgumentExceptionOnInvokeOptional(METHOD_WITH_ARGS_CORRECT_PARAMS, subClass1, new Object());
|
||||
assertIllegalArgumentExceptionOnInvokeOptional(METHOD_WITH_ARGS_CORRECT_PARAMS, subClass1, "one", "two");
|
||||
assertIllegalArgumentExceptionOnInvokeOptional(METHOD_WITH_ARGS_CORRECT_PARAMS, subClass1,
|
||||
true);
|
||||
assertIllegalArgumentExceptionOnInvokeOptional(METHOD_WITH_ARGS_CORRECT_PARAMS, subClass1,
|
||||
new Object());
|
||||
assertIllegalArgumentExceptionOnInvokeOptional(METHOD_WITH_ARGS_CORRECT_PARAMS, subClass1,
|
||||
"one", "two");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -15,16 +15,15 @@
|
||||
*/
|
||||
package okhttp3.internal;
|
||||
|
||||
import okhttp3.Dns;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import okhttp3.Dns;
|
||||
|
||||
/**
|
||||
* A network that resolves only one IP address per host. Use this when testing
|
||||
* route selection fallbacks to prevent the host machine's various IP addresses
|
||||
* from interfering.
|
||||
* A network that resolves only one IP address per host. Use this when testing route selection
|
||||
* fallbacks to prevent the host machine's various IP addresses from interfering.
|
||||
*/
|
||||
public class SingleInetAddressDns implements Dns {
|
||||
@Override public List<InetAddress> lookup(String hostname) throws UnknownHostException {
|
||||
|
||||
@@ -41,8 +41,8 @@ public class HpackTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Variable-length quantity special cases strings which are longer than 127
|
||||
* bytes. Values such as cookies can be 4KiB, and should be possible to send.
|
||||
* Variable-length quantity special cases strings which are longer than 127 bytes. Values such as
|
||||
* cookies can be 4KiB, and should be possible to send.
|
||||
*
|
||||
* <p> http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-12#section-5.2
|
||||
*/
|
||||
@@ -61,8 +61,8 @@ public class HpackTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* HPACK has a max header table size, which can be smaller than the max header message.
|
||||
* Ensure the larger header content is not lost.
|
||||
* HPACK has a max header table size, which can be smaller than the max header message. Ensure the
|
||||
* larger header content is not lost.
|
||||
*/
|
||||
@Test public void tooLargeToHPackIsStillEmitted() throws IOException {
|
||||
bytesIn.writeByte(0x00); // Literal indexed
|
||||
|
||||
@@ -15,17 +15,16 @@
|
||||
*/
|
||||
package okhttp3.internal.framed;
|
||||
|
||||
import okhttp3.internal.Util;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import okhttp3.internal.Util;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSink;
|
||||
import okio.BufferedSource;
|
||||
import okio.ByteString;
|
||||
import okio.GzipSink;
|
||||
import okio.Okio;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static okhttp3.TestUtil.headerEntries;
|
||||
@@ -730,7 +729,7 @@ public class Http2Test {
|
||||
private static List<Header> largeHeaders() {
|
||||
String[] nameValues = new String[32];
|
||||
char[] chars = new char[512];
|
||||
for (int i = 0; i < nameValues.length;) {
|
||||
for (int i = 0; i < nameValues.length; ) {
|
||||
Arrays.fill(chars, (char) i);
|
||||
nameValues[i++] = nameValues[i++] = String.valueOf(chars);
|
||||
}
|
||||
@@ -740,6 +739,6 @@ public class Http2Test {
|
||||
private static void writeMedium(BufferedSink sink, int i) throws IOException {
|
||||
sink.writeByte((i >>> 16) & 0xff);
|
||||
sink.writeByte((i >>> 8) & 0xff);
|
||||
sink.writeByte( i & 0xff);
|
||||
sink.writeByte(i & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package okhttp3.internal.framed;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.PushPromise;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import java.net.HttpURLConnection;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -15,20 +15,6 @@
|
||||
*/
|
||||
package okhttp3.internal.framed;
|
||||
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.ConnectionPool;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.internal.RecordingAuthenticator;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import okhttp3.mockwebserver.SocketPolicy;
|
||||
import okhttp3.testing.RecordingHostnameVerifier;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.Authenticator;
|
||||
@@ -45,6 +31,20 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.ConnectionPool;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.internal.RecordingAuthenticator;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import okhttp3.mockwebserver.SocketPolicy;
|
||||
import okhttp3.testing.RecordingHostnameVerifier;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSink;
|
||||
import okio.GzipSink;
|
||||
@@ -77,7 +77,7 @@ public abstract class HttpOverSpdyTest {
|
||||
protected HttpURLConnection connection;
|
||||
protected Cache cache;
|
||||
|
||||
protected HttpOverSpdyTest(Protocol protocol){
|
||||
protected HttpOverSpdyTest(Protocol protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
@@ -266,16 +266,15 @@ public abstract class HttpOverSpdyTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to ensure we don't throw a read timeout on responses that are
|
||||
* progressing. For this case, we take a 4KiB body and throttle it to
|
||||
* 1KiB/second. We set the read timeout to two seconds. If our
|
||||
* implementation is acting correctly, it will not throw, as it is
|
||||
* progressing.
|
||||
* Test to ensure we don't throw a read timeout on responses that are progressing. For this
|
||||
* case, we take a 4KiB body and throttle it to 1KiB/second. We set the read timeout to two
|
||||
* seconds. If our implementation is acting correctly, it will not throw, as it is progressing.
|
||||
*/
|
||||
@Test public void readTimeoutMoreGranularThanBodySize() throws Exception {
|
||||
char[] body = new char[4096]; // 4KiB to read
|
||||
Arrays.fill(body, 'y');
|
||||
server.enqueue(new MockResponse().setBody(new String(body)).throttleBody(1024, 1, SECONDS)); // slow connection 1KiB/second
|
||||
server.enqueue(new MockResponse().setBody(new String(body))
|
||||
.throttleBody(1024, 1, SECONDS)); // slow connection 1KiB/second
|
||||
|
||||
connection = client.open(server.url("/").url());
|
||||
connection.setReadTimeout(2000); // 2 seconds to read something.
|
||||
@@ -283,11 +282,10 @@ public abstract class HttpOverSpdyTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to ensure we throw a read timeout on responses that are progressing
|
||||
* too slowly. For this case, we take a 2KiB body and throttle it to
|
||||
* 1KiB/second. We set the read timeout to half a second. If our
|
||||
* implementation is acting correctly, it will throw, as a byte doesn't
|
||||
* arrive in time.
|
||||
* Test to ensure we throw a read timeout on responses that are progressing too slowly. For this
|
||||
* case, we take a 2KiB body and throttle it to 1KiB/second. We set the read timeout to half a
|
||||
* second. If our implementation is acting correctly, it will throw, as a byte doesn't arrive in
|
||||
* time.
|
||||
*/
|
||||
@Test public void readTimeoutOnSlowConnection() throws Exception {
|
||||
char[] body = new char[2048]; // 2KiB to read
|
||||
@@ -442,6 +440,7 @@ public abstract class HttpOverSpdyTest {
|
||||
class SpdyRequest implements Runnable {
|
||||
String path;
|
||||
CountDownLatch countDownLatch;
|
||||
|
||||
public SpdyRequest(String path, CountDownLatch countDownLatch) {
|
||||
this.path = path;
|
||||
this.countDownLatch = countDownLatch;
|
||||
|
||||
@@ -83,8 +83,8 @@ public final class MockSpdyPeer implements Closeable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a manually-constructed frame. This is useful to test frames that
|
||||
* won't be generated naturally.
|
||||
* Sends a manually-constructed frame. This is useful to test frames that won't be generated
|
||||
* naturally.
|
||||
*/
|
||||
public void sendFrame(byte[] frame) throws IOException {
|
||||
outFrames.add(new OutFrame(frameCount++, bytesOut.size(), false));
|
||||
@@ -92,9 +92,9 @@ public final class MockSpdyPeer implements Closeable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortens the last frame from its original length to {@code length}. This
|
||||
* will cause the peer to close the socket as soon as this frame has been
|
||||
* written; otherwise the peer stays open until explicitly closed.
|
||||
* Shortens the last frame from its original length to {@code length}. This will cause the peer to
|
||||
* close the socket as soon as this frame has been written; otherwise the peer stays open until
|
||||
* explicitly closed.
|
||||
*/
|
||||
public FrameWriter truncateLastFrame(int length) {
|
||||
OutFrame lastFrame = outFrames.remove(outFrames.size() - 1);
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package okhttp3.internal.framed;
|
||||
|
||||
import okhttp3.internal.Util;
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.net.Socket;
|
||||
@@ -26,6 +25,7 @@ import java.util.Random;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import okhttp3.internal.Util;
|
||||
import okio.AsyncTimeout;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSink;
|
||||
@@ -274,6 +274,7 @@ public final class Spdy3ConnectionTest {
|
||||
@Override public void onStream(FramedStream stream) throws IOException {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Override public void onSettings(FramedConnection connection) {
|
||||
maxConcurrentStreams.set(connection.maxConcurrentStreams());
|
||||
}
|
||||
@@ -475,8 +476,7 @@ public final class Spdy3ConnectionTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the client sends a RST_STREAM if doing so won't disrupt the
|
||||
* output stream.
|
||||
* Test that the client sends a RST_STREAM if doing so won't disrupt the output stream.
|
||||
*/
|
||||
@Test public void clientClosesClientInputStream() throws Exception {
|
||||
// write the mocking script
|
||||
@@ -517,8 +517,7 @@ public final class Spdy3ConnectionTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the client doesn't send a RST_STREAM if doing so will disrupt
|
||||
* the output stream.
|
||||
* Test that the client doesn't send a RST_STREAM if doing so will disrupt the output stream.
|
||||
*/
|
||||
@Test public void clientClosesClientInputStreamIfOutputStreamIsClosed() throws Exception {
|
||||
// write the mocking script
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package okhttp3.internal.framed;
|
||||
|
||||
import okhttp3.internal.Util;
|
||||
import java.io.IOException;
|
||||
import okhttp3.internal.Util;
|
||||
import okio.Buffer;
|
||||
import okio.ByteString;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -16,11 +16,6 @@
|
||||
|
||||
package okhttp3.internal.http;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import java.io.IOException;
|
||||
import java.net.CookieHandler;
|
||||
import java.net.CookieManager;
|
||||
@@ -33,6 +28,11 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -252,10 +252,9 @@ public class CookiesTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test which headers show up where. The cookie manager should be notified
|
||||
* of both user-specified and derived headers like {@code Host}. Headers
|
||||
* named {@code Cookie} or {@code Cookie2} that are returned by the cookie
|
||||
* manager should show up in the request and in {@code
|
||||
* Test which headers show up where. The cookie manager should be notified of both user-specified
|
||||
* and derived headers like {@code Host}. Headers named {@code Cookie} or {@code Cookie2} that are
|
||||
* returned by the cookie manager should show up in the request and in {@code
|
||||
* getRequestProperties}.
|
||||
*/
|
||||
@Test public void testHeadersSentToCookieHandler() throws IOException, InterruptedException {
|
||||
@@ -324,7 +323,7 @@ public class CookiesTest {
|
||||
}
|
||||
});
|
||||
MockWebServer server = new MockWebServer();
|
||||
server. enqueue(new MockResponse());
|
||||
server.enqueue(new MockResponse());
|
||||
server.start();
|
||||
|
||||
get(server, "/");
|
||||
@@ -350,11 +349,10 @@ public class CookiesTest {
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String,List<String>> get(MockWebServer server, String path) throws Exception {
|
||||
private Map<String, List<String>> get(MockWebServer server, String path) throws Exception {
|
||||
URLConnection connection = new OkUrlFactory(client).open(server.url(path).url());
|
||||
Map<String, List<String>> headers = connection.getHeaderFields();
|
||||
connection.getInputStream().close();
|
||||
return headers;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,12 +15,6 @@
|
||||
*/
|
||||
package okhttp3.internal.http;
|
||||
|
||||
import okhttp3.DelegatingServerSocketFactory;
|
||||
import okhttp3.DelegatingSocketFactory;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -28,14 +22,18 @@ import java.net.HttpURLConnection;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.net.ServerSocketFactory;
|
||||
import javax.net.SocketFactory;
|
||||
import okhttp3.DelegatingServerSocketFactory;
|
||||
import okhttp3.DelegatingSocketFactory;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okio.Buffer;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.net.ServerSocketFactory;
|
||||
import javax.net.SocketFactory;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public final class DisconnectTest {
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
package okhttp3.internal.http;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.internal.Util;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
@@ -27,6 +23,10 @@ import java.util.List;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.internal.Util;
|
||||
|
||||
import static okhttp3.internal.http.OkHeaders.SELECTED_PROTOCOL;
|
||||
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
package okhttp3.internal.http;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.internal.Util;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
@@ -27,6 +23,10 @@ import java.util.List;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.internal.Util;
|
||||
|
||||
import static okhttp3.internal.http.OkHeaders.SELECTED_PROTOCOL;
|
||||
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package okhttp3.internal.http;
|
||||
|
||||
import okhttp3.Dns;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import okhttp3.Dns;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
@@ -15,17 +15,17 @@
|
||||
*/
|
||||
package okhttp3.internal.http;
|
||||
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.internal.framed.Header;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.internal.framed.Header;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -15,13 +15,12 @@
|
||||
*/
|
||||
package okhttp3.internal.http;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
*/
|
||||
package okhttp3.internal.http;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
|
||||
@@ -16,20 +16,12 @@
|
||||
package okhttp3.internal.http;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ProxySelector;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.URI;
|
||||
import okhttp3.Address;
|
||||
import okhttp3.Authenticator;
|
||||
import okhttp3.ConnectionSpec;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.Route;
|
||||
import okhttp3.internal.RouteDatabase;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.internal.Util;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.ProxySelector;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -40,6 +32,14 @@ import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import okhttp3.Address;
|
||||
import okhttp3.Authenticator;
|
||||
import okhttp3.ConnectionSpec;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.Route;
|
||||
import okhttp3.internal.RouteDatabase;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.internal.Util;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -335,10 +335,10 @@ public final class RouteSelectorTest {
|
||||
socketAddress = new InetSocketAddress(InetAddress.getByName("localhost"), 1234);
|
||||
assertEquals("127.0.0.1", RouteSelector.getHostString(socketAddress));
|
||||
socketAddress = new InetSocketAddress(
|
||||
InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), 1234);
|
||||
InetAddress.getByAddress(new byte[] {127, 0, 0, 1}), 1234);
|
||||
assertEquals("127.0.0.1", RouteSelector.getHostString(socketAddress));
|
||||
socketAddress = new InetSocketAddress(
|
||||
InetAddress.getByAddress("foobar", new byte[] { 127, 0, 0, 1 }), 1234);
|
||||
InetAddress.getByAddress("foobar", new byte[] {127, 0, 0, 1}), 1234);
|
||||
assertEquals("127.0.0.1", RouteSelector.getHostString(socketAddress));
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ public final class RouteSelectorTest {
|
||||
List<InetAddress> result = new ArrayList<>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
result.add(InetAddress.getByAddress(
|
||||
new byte[] { (byte) prefix, (byte) 0, (byte) 0, (byte) i }));
|
||||
new byte[] {(byte) prefix, (byte) 0, (byte) 0, (byte) i}));
|
||||
}
|
||||
return result;
|
||||
} catch (UnknownHostException e) {
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
package okhttp3.internal.http;
|
||||
|
||||
import okhttp3.Protocol;
|
||||
import java.io.IOException;
|
||||
import java.net.ProtocolException;
|
||||
import okhttp3.Protocol;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -44,9 +44,8 @@ public final class StatusLineTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* This is not defined in the protocol but some servers won't add the leading
|
||||
* empty space when the message is empty.
|
||||
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1
|
||||
* This is not defined in the protocol but some servers won't add the leading empty space when the
|
||||
* message is empty. http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1
|
||||
*/
|
||||
@Test public void emptyMessageAndNoLeadingSpace() throws IOException {
|
||||
int version = 1;
|
||||
|
||||
@@ -15,13 +15,6 @@
|
||||
*/
|
||||
package okhttp3.internal.http;
|
||||
|
||||
import okhttp3.DelegatingServerSocketFactory;
|
||||
import okhttp3.DelegatingSocketFactory;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InterruptedIOException;
|
||||
@@ -30,14 +23,18 @@ import java.net.HttpURLConnection;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.net.ServerSocketFactory;
|
||||
import javax.net.SocketFactory;
|
||||
import okhttp3.DelegatingServerSocketFactory;
|
||||
import okhttp3.DelegatingSocketFactory;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okio.Buffer;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.net.ServerSocketFactory;
|
||||
import javax.net.SocketFactory;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public final class ThreadInterruptTest {
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
|
||||
package okhttp3.internal.tls;
|
||||
|
||||
import okhttp3.internal.Util;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.security.auth.x500.X500Principal;
|
||||
import okhttp3.internal.Util;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -32,8 +32,8 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for our hostname verifier. Most of these tests are from AOSP, which
|
||||
* itself includes tests from the Apache HTTP Client test suite.
|
||||
* Tests for our hostname verifier. Most of these tests are from AOSP, which itself includes tests
|
||||
* from the Apache HTTP Client test suite.
|
||||
*/
|
||||
public final class HostnameVerifierTest {
|
||||
private HostnameVerifier verifier = OkHostnameVerifier.INSTANCE;
|
||||
@@ -144,9 +144,9 @@ public final class HostnameVerifierTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignored due to incompatibilities between Android and Java on how non-ASCII
|
||||
* subject alt names are parsed. Android fails to parse these, which means we
|
||||
* fall back to the CN. The RI does parse them, so the CN is unused.
|
||||
* Ignored due to incompatibilities between Android and Java on how non-ASCII subject alt names
|
||||
* are parsed. Android fails to parse these, which means we fall back to the CN. The RI does parse
|
||||
* them, so the CN is unused.
|
||||
*/
|
||||
@Test @Ignore public void verifyNonAsciiSubjectAlt() throws Exception {
|
||||
// CN=foo.com, subjectAlt=bar.com, subjectAlt=花子.co.jp
|
||||
@@ -329,9 +329,9 @@ public final class HostnameVerifierTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignored due to incompatibilities between Android and Java on how non-ASCII
|
||||
* subject alt names are parsed. Android fails to parse these, which means we
|
||||
* fall back to the CN. The RI does parse them, so the CN is unused.
|
||||
* Ignored due to incompatibilities between Android and Java on how non-ASCII subject alt names
|
||||
* are parsed. Android fails to parse these, which means we fall back to the CN. The RI does parse
|
||||
* them, so the CN is unused.
|
||||
*/
|
||||
@Test @Ignore public void testWilcardNonAsciiSubjectAlt() throws Exception {
|
||||
// CN=*.foo.com, subjectAlt=*.bar.com, subjectAlt=*.花子.co.jp
|
||||
@@ -432,10 +432,9 @@ public final class HostnameVerifierTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Earlier implementations of Android's hostname verifier required that
|
||||
* wildcard names wouldn't match "*.com" or similar. This was a nonstandard
|
||||
* check that we've since dropped. It is the CA's responsibility to not hand
|
||||
* out certificates that match so broadly.
|
||||
* Earlier implementations of Android's hostname verifier required that wildcard names wouldn't
|
||||
* match "*.com" or similar. This was a nonstandard check that we've since dropped. It is the CA's
|
||||
* responsibility to not hand out certificates that match so broadly.
|
||||
*/
|
||||
@Test public void wildcardsDoesNotNeedTwoDots() throws Exception {
|
||||
// openssl req -x509 -nodes -days 36500 -subj '/CN=*.com' -newkey rsa:512 -out cert.pem
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
|
||||
@@ -15,19 +15,19 @@
|
||||
*/
|
||||
package okhttp3;
|
||||
|
||||
import okhttp3.internal.huc.HttpURLConnectionImpl;
|
||||
import okhttp3.internal.huc.HttpsURLConnectionImpl;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLStreamHandler;
|
||||
import java.net.URLStreamHandlerFactory;
|
||||
import okhttp3.internal.huc.HttpURLConnectionImpl;
|
||||
import okhttp3.internal.huc.HttpsURLConnectionImpl;
|
||||
|
||||
/**
|
||||
* @deprecated OkHttp will be dropping its ability to be used with {@link HttpURLConnection} in an
|
||||
* upcoming release. Applications that need this should either downgrade to the system's
|
||||
* built-in {@link HttpURLConnection} or upgrade to OkHttp's Request/Response API.
|
||||
* upcoming release. Applications that need this should either downgrade to the system's built-in
|
||||
* {@link HttpURLConnection} or upgrade to OkHttp's Request/Response API.
|
||||
*/
|
||||
public final class OkUrlFactory implements URLStreamHandlerFactory, Cloneable {
|
||||
private final OkHttpClient client;
|
||||
@@ -41,8 +41,8 @@ public final class OkUrlFactory implements URLStreamHandlerFactory, Cloneable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of this stream handler factory that includes a shallow copy
|
||||
* of the internal {@linkplain OkHttpClient HTTP client}.
|
||||
* Returns a copy of this stream handler factory that includes a shallow copy of the internal
|
||||
* {@linkplain OkHttpClient HTTP client}.
|
||||
*/
|
||||
@Override public OkUrlFactory clone() {
|
||||
return new OkUrlFactory(client.clone());
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
package okhttp3.internal.huc;
|
||||
|
||||
import okhttp3.Handshake;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -32,10 +31,11 @@ import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import okhttp3.Handshake;
|
||||
|
||||
/**
|
||||
* Implement an HTTPS connection by delegating to an HTTP connection for
|
||||
* everything but the HTTPS-specific stuff.
|
||||
* Implement an HTTPS connection by delegating to an HTTP connection for everything but the
|
||||
* HTTPS-specific stuff.
|
||||
*/
|
||||
abstract class DelegatingHttpsURLConnection extends HttpsURLConnection {
|
||||
private final HttpURLConnection delegate;
|
||||
|
||||
@@ -17,29 +17,6 @@
|
||||
|
||||
package okhttp3.internal.huc;
|
||||
|
||||
import okhttp3.Connection;
|
||||
import okhttp3.Handshake;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.Route;
|
||||
import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.Platform;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.internal.Version;
|
||||
import okhttp3.internal.http.HttpDate;
|
||||
import okhttp3.internal.http.HttpEngine;
|
||||
import okhttp3.internal.http.HttpMethod;
|
||||
import okhttp3.internal.http.OkHeaders;
|
||||
import okhttp3.internal.http.RequestException;
|
||||
import okhttp3.internal.http.RetryableSink;
|
||||
import okhttp3.internal.http.RouteException;
|
||||
import okhttp3.internal.http.StatusLine;
|
||||
import okhttp3.internal.http.StreamAllocation;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -63,20 +40,42 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import okhttp3.Connection;
|
||||
import okhttp3.Handshake;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.Route;
|
||||
import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.Platform;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.internal.Version;
|
||||
import okhttp3.internal.http.HttpDate;
|
||||
import okhttp3.internal.http.HttpEngine;
|
||||
import okhttp3.internal.http.HttpMethod;
|
||||
import okhttp3.internal.http.OkHeaders;
|
||||
import okhttp3.internal.http.RequestException;
|
||||
import okhttp3.internal.http.RetryableSink;
|
||||
import okhttp3.internal.http.RouteException;
|
||||
import okhttp3.internal.http.StatusLine;
|
||||
import okhttp3.internal.http.StreamAllocation;
|
||||
import okio.BufferedSink;
|
||||
import okio.Sink;
|
||||
|
||||
/**
|
||||
* This implementation uses HttpEngine to send requests and receive responses.
|
||||
* This class may use multiple HttpEngines to follow redirects, authentication
|
||||
* retries, etc. to retrieve the final response body.
|
||||
* This implementation uses HttpEngine to send requests and receive responses. This class may use
|
||||
* multiple HttpEngines to follow redirects, authentication retries, etc. to retrieve the final
|
||||
* response body.
|
||||
*
|
||||
* <h3>What does 'connected' mean?</h3>
|
||||
* This class inherits a {@code connected} field from the superclass. That field
|
||||
* is <strong>not</strong> used to indicate whether this URLConnection is
|
||||
* currently connected. Instead, it indicates whether a connection has ever been
|
||||
* attempted. Once a connection has been attempted, certain properties (request
|
||||
* header fields, request method, etc.) are immutable.
|
||||
* <h3>What does 'connected' mean?</h3> This class inherits a {@code connected} field from the
|
||||
* superclass. That field is <strong>not</strong> used to indicate whether this URLConnection is
|
||||
* currently connected. Instead, it indicates whether a connection has ever been attempted. Once a
|
||||
* connection has been attempted, certain properties (request header fields, request method, etc.)
|
||||
* are immutable.
|
||||
*/
|
||||
public class HttpURLConnectionImpl extends HttpURLConnection {
|
||||
private static final Set<String> METHODS = new LinkedHashSet<>(
|
||||
@@ -96,14 +95,14 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
|
||||
private Headers responseHeaders;
|
||||
|
||||
/**
|
||||
* The most recently attempted route. This will be null if we haven't sent a
|
||||
* request yet, or if the response comes from a cache.
|
||||
* The most recently attempted route. This will be null if we haven't sent a request yet, or if
|
||||
* the response comes from a cache.
|
||||
*/
|
||||
private Route route;
|
||||
|
||||
/**
|
||||
* The most recently received TLS handshake. This will be null if we haven't
|
||||
* connected yet, or if the most recent connection was HTTP (and not HTTPS).
|
||||
* The most recently received TLS handshake. This will be null if we haven't connected yet, or if
|
||||
* the most recent connection was HTTP (and not HTTPS).
|
||||
*/
|
||||
Handshake handshake;
|
||||
|
||||
@@ -134,8 +133,8 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an input stream from the server in the case of error such as the
|
||||
* requested file (txt, htm, html) is not found on the remote server.
|
||||
* Returns an input stream from the server in the case of error such as the requested file (txt,
|
||||
* htm, html) is not found on the remote server.
|
||||
*/
|
||||
@Override public final InputStream getErrorStream() {
|
||||
try {
|
||||
@@ -176,8 +175,8 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the field at {@code position}. Returns null if there
|
||||
* are fewer than {@code position} headers.
|
||||
* Returns the value of the field at {@code position}. Returns null if there are fewer than {@code
|
||||
* position} headers.
|
||||
*/
|
||||
@Override public final String getHeaderField(int position) {
|
||||
try {
|
||||
@@ -188,9 +187,8 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the field corresponding to the {@code fieldName}, or
|
||||
* null if there is no such field. If the field has multiple values, the
|
||||
* last value is returned.
|
||||
* Returns the value of the field corresponding to the {@code fieldName}, or null if there is no
|
||||
* such field. If the field has multiple values, the last value is returned.
|
||||
*/
|
||||
@Override public final String getHeaderField(String fieldName) {
|
||||
try {
|
||||
@@ -384,9 +382,8 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggressively tries to get the final HTTP response, potentially making
|
||||
* many HTTP requests in the process in order to cope with redirects and
|
||||
* authentication.
|
||||
* Aggressively tries to get the final HTTP response, potentially making many HTTP requests in the
|
||||
* process in order to cope with redirects and authentication.
|
||||
*/
|
||||
private HttpEngine getResponse() throws IOException {
|
||||
initHttpEngine();
|
||||
@@ -440,9 +437,9 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request and optionally reads a response. Returns true if the
|
||||
* request was successfully executed, and false if the request can be
|
||||
* retried. Throws an exception if the request failed permanently.
|
||||
* Sends a request and optionally reads a response. Returns true if the request was successfully
|
||||
* executed, and false if the request can be retried. Throws an exception if the request failed
|
||||
* permanently.
|
||||
*/
|
||||
private boolean execute(boolean readResponse) throws IOException {
|
||||
boolean releaseConnection = true;
|
||||
@@ -503,14 +500,15 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
|
||||
|
||||
/**
|
||||
* Returns true if either:
|
||||
*
|
||||
* <ul>
|
||||
* <li>A specific proxy was explicitly configured for this connection.
|
||||
* <li>The response has already been retrieved, and a proxy was {@link
|
||||
* java.net.ProxySelector selected} in order to get it.
|
||||
* </ul>
|
||||
*
|
||||
* <p><strong>Warning:</strong> This method may return false before attempting
|
||||
* to connect and true afterwards.
|
||||
* <p><strong>Warning:</strong> This method may return false before attempting to connect and true
|
||||
* afterwards.
|
||||
*/
|
||||
@Override public final boolean usingProxy() {
|
||||
Proxy proxy = route != null
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
*/
|
||||
package okhttp3.internal.huc;
|
||||
|
||||
import okhttp3.Handshake;
|
||||
import okhttp3.OkHttpClient;
|
||||
import java.net.URL;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import okhttp3.Handshake;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public final class HttpsURLConnectionImpl extends DelegatingHttpsURLConnection {
|
||||
private final HttpURLConnectionImpl delegate;
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package okhttp3;
|
||||
|
||||
import okhttp3.internal.http.OkHeaders;
|
||||
import okhttp3.internal.io.InMemoryFileSystem;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
@@ -13,6 +9,10 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import okhttp3.internal.http.OkHeaders;
|
||||
import okhttp3.internal.io.InMemoryFileSystem;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okio.BufferedSource;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -44,8 +44,8 @@ public class OkUrlFactoryTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Response code 407 should only come from proxy servers. Android's client
|
||||
* throws if it is sent by an origin server.
|
||||
* Response code 407 should only come from proxy servers. Android's client throws if it is sent by
|
||||
* an origin server.
|
||||
*/
|
||||
@Test public void originServerSends407() throws Exception {
|
||||
server.enqueue(new MockResponse().setResponseCode(407));
|
||||
|
||||
@@ -16,13 +16,6 @@
|
||||
|
||||
package okhttp3;
|
||||
|
||||
import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.internal.io.InMemoryFileSystem;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -52,6 +45,13 @@ import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.internal.io.InMemoryFileSystem;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSink;
|
||||
import okio.GzipSink;
|
||||
@@ -352,10 +352,9 @@ public final class UrlConnectionCacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* We've had bugs where caching and cross-protocol redirects yield class
|
||||
* cast exceptions internal to the cache because we incorrectly assumed that
|
||||
* HttpsURLConnection was always HTTPS and HttpURLConnection was always HTTP;
|
||||
* in practice redirects mean that each can do either.
|
||||
* We've had bugs where caching and cross-protocol redirects yield class cast exceptions internal
|
||||
* to the cache because we incorrectly assumed that HttpsURLConnection was always HTTPS and
|
||||
* HttpURLConnection was always HTTP; in practice redirects mean that each can do either.
|
||||
*
|
||||
* https://github.com/square/okhttp/issues/214
|
||||
*/
|
||||
@@ -1038,8 +1037,8 @@ public final class UrlConnectionCacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm that {@link URLConnection#setIfModifiedSince} causes an
|
||||
* If-Modified-Since header with a GMT timestamp.
|
||||
* Confirm that {@link URLConnection#setIfModifiedSince} causes an If-Modified-Since header with a
|
||||
* GMT timestamp.
|
||||
*
|
||||
* https://code.google.com/p/android/issues/detail?id=66135
|
||||
*/
|
||||
@@ -1056,8 +1055,8 @@ public final class UrlConnectionCacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* For Last-Modified and Date headers, we should echo the date back in the
|
||||
* exact format we were served.
|
||||
* For Last-Modified and Date headers, we should echo the date back in the exact format we were
|
||||
* served.
|
||||
*/
|
||||
@Test public void retainServedDateFormat() throws Exception {
|
||||
// Serve a response with a non-standard date format that OkHttp supports.
|
||||
@@ -1590,10 +1589,9 @@ public final class UrlConnectionCacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Old implementations of OkHttp's response cache wrote header fields like
|
||||
* ":status: 200 OK". This broke our cached response parser because it split
|
||||
* on the first colon. This regression test exists to help us read these old
|
||||
* bad cache entries.
|
||||
* Old implementations of OkHttp's response cache wrote header fields like ":status: 200 OK". This
|
||||
* broke our cached response parser because it split on the first colon. This regression test
|
||||
* exists to help us read these old bad cache entries.
|
||||
*
|
||||
* https://github.com/square/okhttp/issues/227
|
||||
*/
|
||||
@@ -1656,9 +1654,8 @@ public final class UrlConnectionCacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param delta the offset from the current date to use. Negative
|
||||
* values yield dates in the past; positive values yield dates in the
|
||||
* future.
|
||||
* @param delta the offset from the current date to use. Negative values yield dates in the past;
|
||||
* positive values yield dates in the future.
|
||||
*/
|
||||
private String formatDate(long delta, TimeUnit timeUnit) {
|
||||
return formatDate(new Date(System.currentTimeMillis() + timeUnit.toMillis(delta)));
|
||||
@@ -1733,9 +1730,8 @@ public final class UrlConnectionCacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortens the body of {@code response} but not the corresponding headers.
|
||||
* Only useful to test how clients respond to the premature conclusion of
|
||||
* the HTTP body.
|
||||
* Shortens the body of {@code response} but not the corresponding headers. Only useful to test
|
||||
* how clients respond to the premature conclusion of the HTTP body.
|
||||
*/
|
||||
private MockResponse truncateViolently(MockResponse response, int numBytesToKeep) {
|
||||
response.setSocketPolicy(DISCONNECT_AT_END);
|
||||
@@ -1748,9 +1744,8 @@ public final class UrlConnectionCacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads {@code count} characters from the stream. If the stream is
|
||||
* exhausted before {@code count} characters can be read, the remaining
|
||||
* characters are returned and the stream is closed.
|
||||
* Reads {@code count} characters from the stream. If the stream is exhausted before {@code count}
|
||||
* characters can be read, the remaining characters are returned and the stream is closed.
|
||||
*/
|
||||
private String readAscii(URLConnection connection, int count) throws IOException {
|
||||
HttpURLConnection httpConnection = (HttpURLConnection) connection;
|
||||
|
||||
@@ -16,6 +16,12 @@
|
||||
|
||||
package okhttp3.internal.huc;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import okhttp3.Request;
|
||||
@@ -24,28 +30,20 @@ import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.InternalCache;
|
||||
import okhttp3.internal.http.CacheRequest;
|
||||
import okhttp3.internal.http.CacheStrategy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Exercises HttpURLConnection to convert URL to a URI. Unlike URL#toURI,
|
||||
* HttpURLConnection recovers from URLs with unescaped but unsupported URI
|
||||
* characters like '{' and '|' by escaping these characters.
|
||||
* Exercises HttpURLConnection to convert URL to a URI. Unlike URL#toURI, HttpURLConnection recovers
|
||||
* from URLs with unescaped but unsupported URI characters like '{' and '|' by escaping these
|
||||
* characters.
|
||||
*/
|
||||
public final class URLEncodingTest {
|
||||
/**
|
||||
* This test goes through the exhaustive set of interesting ASCII characters
|
||||
* because most of those characters are interesting in some way according to
|
||||
* RFC 2396 and RFC 2732. http://b/1158780
|
||||
* This test goes through the exhaustive set of interesting ASCII characters because most of those
|
||||
* characters are interesting in some way according to RFC 2396 and RFC 2732. http://b/1158780
|
||||
*/
|
||||
@Test @Ignore public void lenientUrlToUri() throws Exception {
|
||||
// alphanum
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
|
||||
@@ -15,12 +15,6 @@
|
||||
*/
|
||||
package okhttp3.ws;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.internal.Version;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -28,6 +22,12 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.internal.Version;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSource;
|
||||
|
||||
@@ -35,8 +35,8 @@ import static okhttp3.ws.WebSocket.BINARY;
|
||||
import static okhttp3.ws.WebSocket.TEXT;
|
||||
|
||||
/**
|
||||
* Exercises the web socket implementation against the
|
||||
* <a href="http://autobahn.ws/testsuite/">Autobahn Testsuite</a>.
|
||||
* Exercises the web socket implementation against the <a
|
||||
* href="http://autobahn.ws/testsuite/">Autobahn Testsuite</a>.
|
||||
*/
|
||||
public final class AutobahnTester {
|
||||
private static final String HOST = "ws://localhost:9001";
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
*/
|
||||
package okhttp3.internal.ws;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ws.WebSocketRecorder;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.net.ProtocolException;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Executor;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ws.WebSocketRecorder;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSink;
|
||||
import okio.BufferedSource;
|
||||
@@ -112,7 +112,7 @@ public final class RealWebSocketTest {
|
||||
@Test public void binaryMessage() throws IOException {
|
||||
client.sendMessage(RequestBody.create(BINARY, "Hello!"));
|
||||
server.readMessage();
|
||||
serverListener.assertBinaryMessage(new byte[] { 'H', 'e', 'l', 'l', 'o', '!' });
|
||||
serverListener.assertBinaryMessage(new byte[] {'H', 'e', 'l', 'l', 'o', '!'});
|
||||
}
|
||||
|
||||
@Test public void missingContentTypeThrows() throws IOException {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user