mirror of
https://github.com/square/okhttp.git
synced 2025-11-23 06:42:24 +03:00
Sort more 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>
|
||||
|
||||
@@ -38,11 +38,11 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.x509.X509V3CertificateGenerator;
|
||||
|
||||
/**
|
||||
* Constructs an SSL context for testing. This uses Bouncy Castle to generate a
|
||||
* self-signed certificate for a single hostname such as "localhost".
|
||||
* Constructs an SSL context for testing. This uses Bouncy Castle to generate a self-signed
|
||||
* certificate for a single hostname such as "localhost".
|
||||
*
|
||||
* <p>The crypto performed by this class is relatively slow. Clients should
|
||||
* reuse SSL context instances where possible.
|
||||
* <p>The crypto performed by this class is relatively slow. Clients should reuse SSL context
|
||||
* instances where possible.
|
||||
*/
|
||||
public final class SslContextBuilder {
|
||||
static {
|
||||
@@ -57,8 +57,8 @@ public final class SslContextBuilder {
|
||||
private long notAfter = System.currentTimeMillis() + ONE_DAY_MILLIS;
|
||||
|
||||
/**
|
||||
* @param hostName the subject of the host. For TLS this should be the
|
||||
* domain name that the client uses to identify the server.
|
||||
* @param hostName the subject of the host. For TLS this should be the domain name that the client
|
||||
* uses to identify the server.
|
||||
*/
|
||||
public SslContextBuilder(String hostName) {
|
||||
this.hostName = hostName;
|
||||
@@ -111,8 +111,8 @@ public final class SslContextBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a certificate for {@code hostName} containing {@code keyPair}'s
|
||||
* public key, signed by {@code keyPair}'s private key.
|
||||
* Generates a certificate for {@code hostName} containing {@code keyPair}'s public key, signed by
|
||||
* {@code keyPair}'s private key.
|
||||
*/
|
||||
@SuppressWarnings("deprecation") // use the old Bouncy Castle APIs to reduce dependencies.
|
||||
public X509Certificate selfSignedCertificate(KeyPair keyPair, String serialNumber)
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
package okhttp3.internal.framed;
|
||||
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.internal.Platform;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.internal.Util;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.ProtocolException;
|
||||
@@ -31,6 +27,10 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.internal.Platform;
|
||||
import okhttp3.internal.SslContextBuilder;
|
||||
import okhttp3.internal.Util;
|
||||
import okio.BufferedSink;
|
||||
import okio.Okio;
|
||||
import okio.Source;
|
||||
|
||||
@@ -18,17 +18,16 @@ package okhttp3.mockwebserver;
|
||||
/** Handler for mock server requests. */
|
||||
public abstract class Dispatcher {
|
||||
/**
|
||||
* Returns a response to satisfy {@code request}. This method may block (for
|
||||
* instance, to wait on a CountdownLatch).
|
||||
* Returns a response to satisfy {@code request}. This method may block (for instance, to wait on
|
||||
* a CountdownLatch).
|
||||
*/
|
||||
public abstract MockResponse dispatch(RecordedRequest request) throws InterruptedException;
|
||||
|
||||
/**
|
||||
* Returns an early guess of the next response, used for policy on how an
|
||||
* incoming request should be received. The default implementation returns an
|
||||
* empty response. Mischievous implementations can return other values to test
|
||||
* HTTP edge cases, such as unhappy socket policies or throttled request
|
||||
* bodies.
|
||||
* Returns an early guess of the next response, used for policy on how an incoming request should
|
||||
* be received. The default implementation returns an empty response. Mischievous implementations
|
||||
* can return other values to test HTTP edge cases, such as unhappy socket policies or throttled
|
||||
* request bodies.
|
||||
*/
|
||||
public MockResponse peek() {
|
||||
return new MockResponse().setSocketPolicy(SocketPolicy.KEEP_OPEN);
|
||||
|
||||
@@ -15,14 +15,13 @@
|
||||
*/
|
||||
package okhttp3.mockwebserver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.framed.Settings;
|
||||
import okhttp3.ws.WebSocketListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import okhttp3.Protocol;
|
||||
import okio.Buffer;
|
||||
|
||||
/** A scripted response to be replayed by the mock web server. */
|
||||
@@ -83,8 +82,8 @@ public final class MockResponse implements Cloneable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all HTTP headers including any "Content-Length" and
|
||||
* "Transfer-encoding" headers that were added by default.
|
||||
* Removes all HTTP headers including any "Content-Length" and "Transfer-encoding" headers that
|
||||
* were added by default.
|
||||
*/
|
||||
public MockResponse clearHeaders() {
|
||||
headers = new Headers.Builder();
|
||||
@@ -92,8 +91,8 @@ public final class MockResponse implements Cloneable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds {@code header} as an HTTP header. For well-formed HTTP {@code header}
|
||||
* should contain a name followed by a colon and a value.
|
||||
* Adds {@code header} as an HTTP header. For well-formed HTTP {@code header} should contain a
|
||||
* name followed by a colon and a value.
|
||||
*/
|
||||
public MockResponse addHeader(String header) {
|
||||
headers.add(header);
|
||||
@@ -101,8 +100,8 @@ public final class MockResponse implements Cloneable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new header with the name and value. This may be used to add multiple
|
||||
* headers with the same name.
|
||||
* Adds a new header with the name and value. This may be used to add multiple headers with the
|
||||
* same name.
|
||||
*/
|
||||
public MockResponse addHeader(String name, Object value) {
|
||||
headers.add(name, String.valueOf(value));
|
||||
@@ -110,9 +109,9 @@ public final class MockResponse implements Cloneable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new header with the name and value. This may be used to add multiple
|
||||
* headers with the same name. Unlike {@link #addHeader(String, Object)} this
|
||||
* does not validate the name and value.
|
||||
* Adds a new header with the name and value. This may be used to add multiple headers with the
|
||||
* same name. Unlike {@link #addHeader(String, Object)} this does not validate the name and
|
||||
* value.
|
||||
*/
|
||||
public MockResponse addHeaderLenient(String name, Object value) {
|
||||
Internal.instance.addLenient(headers, name, String.valueOf(value));
|
||||
@@ -120,8 +119,7 @@ public final class MockResponse implements Cloneable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all headers named {@code name}, then adds a new header with the
|
||||
* name and value.
|
||||
* Removes all headers named {@code name}, then adds a new header with the name and value.
|
||||
*/
|
||||
public MockResponse setHeader(String name, Object value) {
|
||||
removeHeader(name);
|
||||
@@ -157,8 +155,7 @@ public final class MockResponse implements Cloneable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the response body to {@code body}, chunked every {@code maxChunkSize}
|
||||
* bytes.
|
||||
* Sets the response body to {@code body}, chunked every {@code maxChunkSize} bytes.
|
||||
*/
|
||||
public MockResponse setChunkedBody(Buffer body, int maxChunkSize) {
|
||||
removeHeader("Content-Length");
|
||||
@@ -179,8 +176,8 @@ public final class MockResponse implements Cloneable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the response body to the UTF-8 encoded bytes of {@code body}, chunked
|
||||
* every {@code maxChunkSize} bytes.
|
||||
* Sets the response body to the UTF-8 encoded bytes of {@code body}, chunked every {@code
|
||||
* maxChunkSize} bytes.
|
||||
*/
|
||||
public MockResponse setChunkedBody(String body, int maxChunkSize) {
|
||||
return setChunkedBody(new Buffer().writeUtf8(body), maxChunkSize);
|
||||
@@ -215,8 +212,8 @@ public final class MockResponse implements Cloneable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the delayed time of the response body to {@code delay}. This applies to the
|
||||
* response body only; response headers are not affected.
|
||||
* Set the delayed time of the response body to {@code delay}. This applies to the response body
|
||||
* only; response headers are not affected.
|
||||
*/
|
||||
public MockResponse setBodyDelay(long delay, TimeUnit unit) {
|
||||
bodyDelayAmount = delay;
|
||||
@@ -229,9 +226,8 @@ public final class MockResponse implements Cloneable {
|
||||
}
|
||||
|
||||
/**
|
||||
* When {@link MockWebServer#setProtocols(java.util.List) protocols}
|
||||
* include {@linkplain Protocol#HTTP_2}, this attaches a
|
||||
* pushed stream to this response.
|
||||
* When {@link MockWebServer#setProtocols(java.util.List) protocols} include {@linkplain
|
||||
* okhttp3.Protocol#HTTP_2}, this attaches a pushed stream to this response.
|
||||
*/
|
||||
public MockResponse withPush(PushPromise promise) {
|
||||
this.promises.add(promise);
|
||||
@@ -244,9 +240,8 @@ public final class MockResponse implements Cloneable {
|
||||
}
|
||||
|
||||
/**
|
||||
* When {@linkplain MockWebServer#setProtocols(java.util.List) protocols}
|
||||
* include {@linkplain Protocol#HTTP_2 HTTP/2}, this
|
||||
* pushes {@code settings} before writing the response.
|
||||
* When {@linkplain MockWebServer#setProtocols(java.util.List) protocols} include {@linkplain
|
||||
* okhttp3.Protocol#HTTP_2 HTTP/2}, this pushes {@code settings} before writing the response.
|
||||
*/
|
||||
public MockResponse withSettings(Settings settings) {
|
||||
this.settings = settings;
|
||||
|
||||
@@ -17,23 +17,6 @@
|
||||
|
||||
package okhttp3.mockwebserver;
|
||||
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.internal.NamedRunnable;
|
||||
import okhttp3.internal.Platform;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.internal.framed.ErrorCode;
|
||||
import okhttp3.internal.framed.FramedConnection;
|
||||
import okhttp3.internal.framed.FramedStream;
|
||||
import okhttp3.internal.framed.Header;
|
||||
import okhttp3.internal.framed.Settings;
|
||||
import okhttp3.internal.http.HttpMethod;
|
||||
import okhttp3.internal.ws.RealWebSocket;
|
||||
import okhttp3.internal.ws.WebSocketProtocol;
|
||||
import okhttp3.ws.WebSocketListener;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -69,6 +52,23 @@ import javax.net.ssl.SSLSocket;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.internal.NamedRunnable;
|
||||
import okhttp3.internal.Platform;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.internal.framed.ErrorCode;
|
||||
import okhttp3.internal.framed.FramedConnection;
|
||||
import okhttp3.internal.framed.FramedStream;
|
||||
import okhttp3.internal.framed.Header;
|
||||
import okhttp3.internal.framed.Settings;
|
||||
import okhttp3.internal.http.HttpMethod;
|
||||
import okhttp3.internal.ws.RealWebSocket;
|
||||
import okhttp3.internal.ws.WebSocketProtocol;
|
||||
import okhttp3.ws.WebSocketListener;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSink;
|
||||
import okio.BufferedSource;
|
||||
@@ -93,8 +93,8 @@ import static okhttp3.mockwebserver.SocketPolicy.SHUTDOWN_OUTPUT_AT_END;
|
||||
import static okhttp3.mockwebserver.SocketPolicy.UPGRADE_TO_SSL_AT_END;
|
||||
|
||||
/**
|
||||
* A scriptable web server. Callers supply canned responses and the server
|
||||
* replays them upon request in sequence.
|
||||
* A scriptable web server. Callers supply canned responses and the server replays them upon request
|
||||
* in sequence.
|
||||
*/
|
||||
public final class MockWebServer implements TestRule {
|
||||
private static final X509TrustManager UNTRUSTED_TRUST_MANAGER = new X509TrustManager() {
|
||||
@@ -202,9 +202,8 @@ public final class MockWebServer implements TestRule {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a cookie domain for this server. This returns the server's
|
||||
* non-loopback host name if it is known. Otherwise this returns ".local" for
|
||||
* this server's loopback name.
|
||||
* Returns a cookie domain for this server. This returns the server's non-loopback host name if it
|
||||
* is known. Otherwise this returns ".local" for this server's loopback name.
|
||||
*/
|
||||
public String getCookieDomain() {
|
||||
String hostName = getHostName();
|
||||
@@ -212,29 +211,26 @@ public final class MockWebServer implements TestRule {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of bytes of the POST body to keep in memory to the given
|
||||
* limit.
|
||||
* Sets the number of bytes of the POST body to keep in memory to the given limit.
|
||||
*/
|
||||
public void setBodyLimit(long maxBodyLength) {
|
||||
this.bodyLimit = maxBodyLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether ALPN is used on incoming HTTPS connections to
|
||||
* negotiate a protocol like HTTP/1.1 or HTTP/2. Call this method to disable
|
||||
* negotiation and restrict connections to HTTP/1.1.
|
||||
* Sets whether ALPN is used on incoming HTTPS connections to negotiate a protocol like HTTP/1.1
|
||||
* or HTTP/2. Call this method to disable negotiation and restrict connections to HTTP/1.1.
|
||||
*/
|
||||
public void setProtocolNegotiationEnabled(boolean protocolNegotiationEnabled) {
|
||||
this.protocolNegotiationEnabled = protocolNegotiationEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates the protocols supported by ALPN on incoming HTTPS
|
||||
* connections. This list is ignored when
|
||||
* {@link #setProtocolNegotiationEnabled negotiation is disabled}.
|
||||
* Indicates the protocols supported by ALPN on incoming HTTPS connections. This list is ignored
|
||||
* when {@link #setProtocolNegotiationEnabled negotiation is disabled}.
|
||||
*
|
||||
* @param protocols the protocols to use, in order of preference. The list
|
||||
* must contain {@linkplain Protocol#HTTP_1_1}. It must not contain null.
|
||||
* @param protocols the protocols to use, in order of preference. The list must contain
|
||||
* {@linkplain Protocol#HTTP_1_1}. It must not contain null.
|
||||
*/
|
||||
public void setProtocols(List<Protocol> protocols) {
|
||||
protocols = Util.immutableList(protocols);
|
||||
@@ -250,8 +246,7 @@ public final class MockWebServer implements TestRule {
|
||||
/**
|
||||
* Serve requests with HTTPS rather than otherwise.
|
||||
*
|
||||
* @param tunnelProxy true to expect the HTTP CONNECT method before
|
||||
* negotiating TLS.
|
||||
* @param tunnelProxy true to expect the HTTP CONNECT method before negotiating TLS.
|
||||
*/
|
||||
public void useHttps(SSLSocketFactory sslSocketFactory, boolean tunnelProxy) {
|
||||
this.sslSocketFactory = sslSocketFactory;
|
||||
@@ -259,9 +254,9 @@ public final class MockWebServer implements TestRule {
|
||||
}
|
||||
|
||||
/**
|
||||
* Awaits the next HTTP request, removes it, and returns it. Callers should
|
||||
* use this to verify the request was sent as intended. This method will block until the
|
||||
* request is available, possibly forever.
|
||||
* Awaits the next HTTP request, removes it, and returns it. Callers should use this to verify the
|
||||
* request was sent as intended. This method will block until the request is available, possibly
|
||||
* forever.
|
||||
*
|
||||
* @return the head of the request queue
|
||||
*/
|
||||
@@ -270,14 +265,12 @@ public final class MockWebServer implements TestRule {
|
||||
}
|
||||
|
||||
/**
|
||||
* Awaits the next HTTP request (waiting up to the
|
||||
* specified wait time if necessary), removes it, and returns it. Callers should
|
||||
* use this to verify the request was sent as intended within the given time.
|
||||
* Awaits the next HTTP request (waiting up to the specified wait time if necessary), removes it,
|
||||
* and returns it. Callers should use this to verify the request was sent as intended within the
|
||||
* given time.
|
||||
*
|
||||
* @param timeout how long to wait before giving up, in units of
|
||||
* {@code unit}
|
||||
* @param unit a {@code TimeUnit} determining how to interpret the
|
||||
* {@code timeout} parameter
|
||||
* @param timeout how long to wait before giving up, in units of {@code unit}
|
||||
* @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter
|
||||
* @return the head of the request queue
|
||||
*/
|
||||
public RecordedRequest takeRequest(long timeout, TimeUnit unit) throws InterruptedException {
|
||||
@@ -285,21 +278,20 @@ public final class MockWebServer implements TestRule {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of HTTP requests received thus far by this server. This
|
||||
* may exceed the number of HTTP connections when connection reuse is in
|
||||
* practice.
|
||||
* Returns the number of HTTP requests received thus far by this server. This may exceed the
|
||||
* number of HTTP connections when connection reuse is in practice.
|
||||
*/
|
||||
public int getRequestCount() {
|
||||
return requestCount.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Scripts {@code response} to be returned to a request made in sequence. The
|
||||
* first request is served by the first enqueued response; the second request
|
||||
* by the second enqueued response; and so on.
|
||||
* Scripts {@code response} to be returned to a request made in sequence. The first request is
|
||||
* served by the first enqueued response; the second request by the second enqueued response; and
|
||||
* so on.
|
||||
*
|
||||
* @throws ClassCastException if the default dispatcher has been replaced
|
||||
* with {@link #setDispatcher(Dispatcher)}.
|
||||
* @throws ClassCastException if the default dispatcher has been replaced with {@link
|
||||
* #setDispatcher(Dispatcher)}.
|
||||
*/
|
||||
public void enqueue(MockResponse response) {
|
||||
((QueueDispatcher) dispatcher).enqueueResponse(response.clone());
|
||||
@@ -313,9 +305,8 @@ public final class MockWebServer implements TestRule {
|
||||
/**
|
||||
* Starts the server on the loopback interface for the given port.
|
||||
*
|
||||
* @param port the port to listen to, or 0 for any available port. Automated
|
||||
* tests should always use port 0 to avoid flakiness when a specific port
|
||||
* is unavailable.
|
||||
* @param port the port to listen to, or 0 for any available port. Automated tests should always
|
||||
* use port 0 to avoid flakiness when a specific port is unavailable.
|
||||
*/
|
||||
public void start(int port) throws IOException {
|
||||
start(InetAddress.getByName("localhost"), port);
|
||||
@@ -325,9 +316,8 @@ public final class MockWebServer implements TestRule {
|
||||
* Starts the server on the given address and port.
|
||||
*
|
||||
* @param inetAddress the address to create the server socket on
|
||||
* @param port the port to listen to, or 0 for any available port. Automated
|
||||
* tests should always use port 0 to avoid flakiness when a specific port
|
||||
* is unavailable.
|
||||
* @param port the port to listen to, or 0 for any available port. Automated tests should always
|
||||
* use port 0 to avoid flakiness when a specific port is unavailable.
|
||||
*/
|
||||
public void start(InetAddress inetAddress, int port) throws IOException {
|
||||
start(new InetSocketAddress(inetAddress, port));
|
||||
@@ -743,9 +733,9 @@ public final class MockWebServer implements TestRule {
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfer bytes from {@code source} to {@code sink} until either {@code byteCount}
|
||||
* bytes have been transferred or {@code source} is exhausted. The transfer is
|
||||
* throttled according to {@code policy}.
|
||||
* Transfer bytes from {@code source} to {@code sink} until either {@code byteCount} bytes have
|
||||
* been transferred or {@code source} is exhausted. The transfer is throttled according to {@code
|
||||
* policy}.
|
||||
*/
|
||||
private void throttledTransfer(MockResponse policy, Socket socket, BufferedSource source,
|
||||
BufferedSink sink, long byteCount, boolean isRequest) throws IOException {
|
||||
@@ -801,10 +791,9 @@ public final class MockWebServer implements TestRule {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the dispatcher used to match incoming requests to mock responses.
|
||||
* The default dispatcher simply serves a fixed sequence of responses from
|
||||
* a {@link #enqueue(MockResponse) queue}; custom dispatchers can vary the
|
||||
* response based on timing or the content of the request.
|
||||
* Sets the dispatcher used to match incoming requests to mock responses. The default dispatcher
|
||||
* simply serves a fixed sequence of responses from a {@link #enqueue(MockResponse) queue}; custom
|
||||
* dispatchers can vary the response based on timing or the content of the request.
|
||||
*/
|
||||
public void setDispatcher(Dispatcher dispatcher) {
|
||||
if (dispatcher == null) throw new NullPointerException();
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Default dispatcher that processes a script of responses. Populate the script
|
||||
* by calling {@link #enqueueResponse(MockResponse)}.
|
||||
* Default dispatcher that processes a script of responses. Populate the script by calling {@link
|
||||
* #enqueueResponse(MockResponse)}.
|
||||
*/
|
||||
public class QueueDispatcher extends Dispatcher {
|
||||
private static final Logger logger = Logger.getLogger(QueueDispatcher.class.getName());
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
package okhttp3.mockwebserver;
|
||||
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.TlsVersion;
|
||||
import java.net.Socket;
|
||||
import java.util.List;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.TlsVersion;
|
||||
import okio.Buffer;
|
||||
|
||||
/** An HTTP request that came into the mock web server. */
|
||||
@@ -82,16 +82,15 @@ public final class RecordedRequest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sizes of the chunks of this request's body, or an empty list
|
||||
* if the request's body was empty or unchunked.
|
||||
* Returns the sizes of the chunks of this request's body, or an empty list if the request's body
|
||||
* was empty or unchunked.
|
||||
*/
|
||||
public List<Integer> getChunkSizes() {
|
||||
return chunkSizes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total size of the body of this POST request (before
|
||||
* truncation).
|
||||
* Returns the total size of the body of this POST request (before truncation).
|
||||
*/
|
||||
public long getBodySize() {
|
||||
return bodySize;
|
||||
@@ -108,9 +107,8 @@ public final class RecordedRequest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of this request on its HTTP connection. Since a single
|
||||
* HTTP connection may serve multiple requests, each request is assigned its
|
||||
* own sequence number.
|
||||
* Returns the index of this request on its HTTP connection. Since a single HTTP connection may
|
||||
* serve multiple requests, each request is assigned its own sequence number.
|
||||
*/
|
||||
public int getSequenceNumber() {
|
||||
return sequenceNumber;
|
||||
|
||||
@@ -32,35 +32,32 @@ package okhttp3.mockwebserver;
|
||||
public enum SocketPolicy {
|
||||
|
||||
/**
|
||||
* Keep the socket open after the response. This is the default HTTP/1.1
|
||||
* behavior.
|
||||
* Keep the socket open after the response. This is the default HTTP/1.1 behavior.
|
||||
*/
|
||||
KEEP_OPEN,
|
||||
|
||||
/**
|
||||
* Close the socket after the response. This is the default HTTP/1.0
|
||||
* behavior.
|
||||
* Close the socket after the response. This is the default HTTP/1.0 behavior.
|
||||
*
|
||||
* <p>See {@link SocketPolicy} for reasons why this can cause test flakiness and how to avoid it.
|
||||
*/
|
||||
DISCONNECT_AT_END,
|
||||
|
||||
/**
|
||||
* Wrap the socket with SSL at the completion of this request/response pair.
|
||||
* Used for CONNECT messages to tunnel SSL over an HTTP proxy.
|
||||
* Wrap the socket with SSL at the completion of this request/response pair. Used for CONNECT
|
||||
* messages to tunnel SSL over an HTTP proxy.
|
||||
*/
|
||||
UPGRADE_TO_SSL_AT_END,
|
||||
|
||||
/**
|
||||
* Request immediate close of connection without even reading the request. Use
|
||||
* to simulate buggy SSL servers closing connections in response to
|
||||
* unrecognized TLS extensions.
|
||||
* Request immediate close of connection without even reading the request. Use to simulate buggy
|
||||
* SSL servers closing connections in response to unrecognized TLS extensions.
|
||||
*/
|
||||
DISCONNECT_AT_START,
|
||||
|
||||
/**
|
||||
* Close connection after reading the request but before writing the response.
|
||||
* Use this to simulate late connection pool failures.
|
||||
* Close connection after reading the request but before writing the response. Use this to
|
||||
* simulate late connection pool failures.
|
||||
*/
|
||||
DISCONNECT_AFTER_REQUEST,
|
||||
|
||||
@@ -74,24 +71,22 @@ public enum SocketPolicy {
|
||||
FAIL_HANDSHAKE,
|
||||
|
||||
/**
|
||||
* Shutdown the socket input after sending the response. For testing bad
|
||||
* behavior.
|
||||
* Shutdown the socket input after sending the response. For testing bad behavior.
|
||||
*
|
||||
* <p>See {@link SocketPolicy} for reasons why this can cause test flakiness and how to avoid it.
|
||||
*/
|
||||
SHUTDOWN_INPUT_AT_END,
|
||||
|
||||
/**
|
||||
* Shutdown the socket output after sending the response. For testing bad
|
||||
* behavior.
|
||||
* Shutdown the socket output after sending the response. For testing bad behavior.
|
||||
*
|
||||
* <p>See {@link SocketPolicy} for reasons why this can cause test flakiness and how to avoid it.
|
||||
*/
|
||||
SHUTDOWN_OUTPUT_AT_END,
|
||||
|
||||
/**
|
||||
* Don't respond to the request but keep the socket open. For testing
|
||||
* read response header timeout issue.
|
||||
* Don't respond to the request but keep the socket open. For testing read response header timeout
|
||||
* issue.
|
||||
*/
|
||||
NO_RESPONSE
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package okhttp3.mockwebserver;
|
||||
|
||||
import okhttp3.Headers;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -32,6 +31,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import okhttp3.Headers;
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -115,8 +115,8 @@ public final class MockWebServerTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that MockWebServer blocks for a call to enqueue() if a request
|
||||
* is made before a mock response is ready.
|
||||
* Test that MockWebServer blocks for a call to enqueue() if a request is made before a mock
|
||||
* response is ready.
|
||||
*/
|
||||
@Test public void dispatchBlocksWaitingForEnqueue() throws Exception {
|
||||
new Thread() {
|
||||
@@ -192,8 +192,8 @@ public final class MockWebServerTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Throttle the request body by sleeping 500ms after every 3 bytes. With a
|
||||
* 6-byte request, this should yield one sleep for a total delay of 500ms.
|
||||
* Throttle the request body by sleeping 500ms after every 3 bytes. With a 6-byte request, this
|
||||
* should yield one sleep for a total delay of 500ms.
|
||||
*/
|
||||
@Test public void throttleRequest() throws Exception {
|
||||
server.enqueue(new MockResponse()
|
||||
@@ -213,8 +213,8 @@ public final class MockWebServerTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Throttle the response body by sleeping 500ms after every 3 bytes. With a
|
||||
* 6-byte response, this should yield one sleep for a total delay of 500ms.
|
||||
* Throttle the response body by sleeping 500ms after every 3 bytes. With a 6-byte response, this
|
||||
* should yield one sleep for a total delay of 500ms.
|
||||
*/
|
||||
@Test public void throttleResponse() throws Exception {
|
||||
server.enqueue(new MockResponse()
|
||||
|
||||
@@ -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.sample;
|
||||
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.internal.NamedRunnable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
@@ -31,6 +25,12 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.internal.NamedRunnable;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
|
||||
@@ -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,9 +1,9 @@
|
||||
package okhttp3.guide;
|
||||
|
||||
import java.io.IOException;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import java.io.IOException;
|
||||
|
||||
public class GetExample {
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package okhttp3.guide;
|
||||
|
||||
import java.io.IOException;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PostExample {
|
||||
public static final MediaType JSON
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import java.io.IOException;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class AccessHeaders {
|
||||
private final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import java.io.IOException;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class AsynchronousGet {
|
||||
private final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class CacheResponse {
|
||||
private final OkHttpClient client;
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class CancelCall {
|
||||
private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.cert.Certificate;
|
||||
import okhttp3.CertificatePinner;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import java.io.IOException;
|
||||
import java.security.cert.Certificate;
|
||||
|
||||
public final class CertificatePinning {
|
||||
private final OkHttpClient client;
|
||||
|
||||
@@ -15,15 +15,15 @@
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.cert.Certificate;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import okhttp3.CertificatePinner;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import java.io.IOException;
|
||||
import java.security.cert.Certificate;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
public final class CheckHandshake {
|
||||
/** Rejects otherwise-trusted certificates. */
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class ConfigureTimeouts {
|
||||
private final OkHttpClient client;
|
||||
|
||||
@@ -15,11 +15,6 @@
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import okhttp3.CertificatePinner;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.GeneralSecurityException;
|
||||
@@ -31,6 +26,11 @@ import java.util.Collection;
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import okhttp3.CertificatePinner;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okio.Buffer;
|
||||
|
||||
public final class CustomTrust {
|
||||
@@ -150,8 +150,9 @@ public final class CustomTrust {
|
||||
* the host platform's built-in trust store.
|
||||
*
|
||||
* <h3>Warning: Customizing Trusted Certificates is Dangerous!</h3>
|
||||
* Relying on your own trusted certificates limits your server team's ability to update their TLS
|
||||
* certificates. By installing a specific set of trusted certificates, you take on additional
|
||||
*
|
||||
* <p>Relying on your own trusted certificates limits your server team's ability to update their
|
||||
* TLS certificates. By installing a specific set of trusted certificates, you take on additional
|
||||
* operational complexity and limit your ability to migrate between certificate authorities. Do
|
||||
* not use custom trusted certificates in production without the blessing of your server's TLS
|
||||
* administrator.
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public final class LoggingInterceptors {
|
||||
private static final Logger logger = Logger.getLogger(LoggingInterceptors.class.getName());
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
package okhttp3.recipes;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public final class ParseResponseWithGson {
|
||||
private final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class PerCallSettings {
|
||||
private final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class PostFile {
|
||||
public static final MediaType MEDIA_TYPE_MARKDOWN
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import java.io.IOException;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class PostForm {
|
||||
private final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
@@ -15,20 +15,19 @@
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class PostMultipart {
|
||||
/**
|
||||
* The imgur client ID for OkHttp recipes. If you're using imgur for anything
|
||||
* other than running these examples, please request your own client ID!
|
||||
* https://api.imgur.com/oauth2
|
||||
* The imgur client ID for OkHttp recipes. If you're using imgur for anything other than running
|
||||
* these examples, please request your own client ID! https://api.imgur.com/oauth2
|
||||
*/
|
||||
private static final String IMGUR_CLIENT_ID = "9199fdef135c122";
|
||||
private static final MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png");
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import java.io.IOException;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import java.io.IOException;
|
||||
import okio.BufferedSink;
|
||||
|
||||
public final class PostStreaming {
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import java.io.IOException;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class PostString {
|
||||
public static final MediaType MEDIA_TYPE_MARKDOWN
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import java.io.IOException;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.Request;
|
||||
import java.io.IOException;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSource;
|
||||
import okio.ForwardingSource;
|
||||
@@ -94,6 +94,7 @@ public final class Progress {
|
||||
private Source source(Source source) {
|
||||
return new ForwardingSource(source) {
|
||||
long totalBytesRead = 0L;
|
||||
|
||||
@Override public long read(Buffer sink, long byteCount) throws IOException {
|
||||
long bytesRead = super.read(sink, byteCount);
|
||||
// read() returns the number of bytes read, or -1 if this source is exhausted.
|
||||
|
||||
@@ -16,15 +16,15 @@
|
||||
package okhttp3.recipes;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import okio.BufferedSink;
|
||||
import okio.GzipSink;
|
||||
import okio.Okio;
|
||||
@@ -33,6 +33,7 @@ public final class RequestBodyCompression {
|
||||
/**
|
||||
* The Google API KEY for OkHttp recipes. If you're using Google APIs for anything other than
|
||||
* running these examples, please request your own client ID!
|
||||
*
|
||||
* https://console.developers.google.com/project
|
||||
*/
|
||||
public static final String GOOGLE_API_KEY = "AIzaSyAx2WZYe0My0i-uGurpvraYJxO7XNbwiGs";
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class RewriteResponseCacheControl {
|
||||
/** Dangerous interceptor that rewrites the server's cache-control header. */
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import java.io.IOException;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class SynchronousGet {
|
||||
private final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package okhttp3.recipes;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
@@ -8,9 +11,6 @@ import okhttp3.ResponseBody;
|
||||
import okhttp3.ws.WebSocket;
|
||||
import okhttp3.ws.WebSocketCall;
|
||||
import okhttp3.ws.WebSocketListener;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import okio.Buffer;
|
||||
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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -2,14 +2,14 @@ package okhttp3.sample;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import java.io.Reader;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
public class OkHttpContributors {
|
||||
private static final String ENDPOINT = "https://api.github.com/repos/square/okhttp/contributors";
|
||||
|
||||
@@ -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>
|
||||
@@ -31,7 +33,8 @@
|
||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||
<shadedClassifierName>shaded</shadedClassifierName>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<manifestEntries>
|
||||
<Main-Class>okhttp3.sample.SampleServer</Main-Class>
|
||||
</manifestEntries>
|
||||
@@ -51,7 +54,9 @@
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals><goal>shade</goal></goals>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package okhttp3.sample;
|
||||
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.mockwebserver.Dispatcher;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -16,6 +11,11 @@ import java.security.SecureRandom;
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.mockwebserver.Dispatcher;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import okio.Buffer;
|
||||
import okio.Okio;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user