mirror of
https://github.com/square/okhttp.git
synced 2025-08-07 12:42:57 +03:00
Drop the get prefix on Connection accessors.
This commit is contained in:
@@ -149,7 +149,7 @@ public final class HttpLoggingInterceptor implements Interceptor {
|
|||||||
boolean hasRequestBody = requestBody != null;
|
boolean hasRequestBody = requestBody != null;
|
||||||
|
|
||||||
Connection connection = chain.connection();
|
Connection connection = chain.connection();
|
||||||
Protocol protocol = connection != null ? connection.getProtocol() : Protocol.HTTP_1_1;
|
Protocol protocol = connection != null ? connection.protocol() : Protocol.HTTP_1_1;
|
||||||
String requestStartMessage =
|
String requestStartMessage =
|
||||||
"--> " + request.method() + ' ' + request.url() + ' ' + protocol(protocol);
|
"--> " + request.method() + ' ' + request.url() + ' ' + protocol(protocol);
|
||||||
if (!logHeaders && hasRequestBody) {
|
if (!logHeaders && hasRequestBody) {
|
||||||
|
@@ -172,7 +172,7 @@ public final class ConnectionPoolTest {
|
|||||||
|
|
||||||
/** Use a helper method so there's no hidden reference remaining on the stack. */
|
/** Use a helper method so there's no hidden reference remaining on the stack. */
|
||||||
private void allocateAndLeakAllocation(ConnectionPool pool, RealConnection connection) {
|
private void allocateAndLeakAllocation(ConnectionPool pool, RealConnection connection) {
|
||||||
StreamAllocation leak = new StreamAllocation(pool, connection.getRoute().address());
|
StreamAllocation leak = new StreamAllocation(pool, connection.route().address());
|
||||||
leak.acquire(connection);
|
leak.acquire(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -134,7 +134,7 @@ public final class InterceptorTest {
|
|||||||
|
|
||||||
Interceptor interceptor = new Interceptor() {
|
Interceptor interceptor = new Interceptor() {
|
||||||
@Override public Response intercept(Chain chain) throws IOException {
|
@Override public Response intercept(Chain chain) throws IOException {
|
||||||
Address address = chain.connection().getRoute().address();
|
Address address = chain.connection().route().address();
|
||||||
String sameHost = address.url().host();
|
String sameHost = address.url().host();
|
||||||
int differentPort = address.url().port() + 1;
|
int differentPort = address.url().port() + 1;
|
||||||
return chain.proceed(chain.request().newBuilder()
|
return chain.proceed(chain.request().newBuilder()
|
||||||
|
@@ -450,8 +450,8 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
|
|||||||
httpEngine.sendRequest();
|
httpEngine.sendRequest();
|
||||||
Connection connection = httpEngine.getConnection();
|
Connection connection = httpEngine.getConnection();
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
route = connection.getRoute();
|
route = connection.route();
|
||||||
handshake = connection.getHandshake();
|
handshake = connection.handshake();
|
||||||
} else {
|
} else {
|
||||||
route = null;
|
route = null;
|
||||||
handshake = null;
|
handshake = null;
|
||||||
|
@@ -65,20 +65,25 @@ import java.net.Socket;
|
|||||||
*/
|
*/
|
||||||
public interface Connection {
|
public interface Connection {
|
||||||
/** Returns the route used by this connection. */
|
/** Returns the route used by this connection. */
|
||||||
Route getRoute();
|
Route route();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the socket that this connection uses, or null if the connection
|
* Returns the socket that this connection is using. Returns an {@linkplain
|
||||||
* is not currently connected.
|
* javax.net.ssl.SSLSocket SSL socket} if this connection is HTTPS. If this is an HTTP/2 or SPDY
|
||||||
|
* connection the socket may be shared by multiple concurrent calls.
|
||||||
*/
|
*/
|
||||||
Socket getSocket();
|
Socket socket();
|
||||||
|
|
||||||
Handshake getHandshake();
|
/**
|
||||||
|
* Returns the TLS handshake used to establish this connection, or null if the connection is not
|
||||||
|
* HTTPS.
|
||||||
|
*/
|
||||||
|
Handshake handshake();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the protocol negotiated by this connection, or {@link Protocol#HTTP_1_1} if no protocol
|
* Returns the protocol negotiated by this connection, or {@link Protocol#HTTP_1_1} if no protocol
|
||||||
* has been negotiated. This method returns {@link Protocol#HTTP_1_1} even if the remote peer is
|
* has been negotiated. This method returns {@link Protocol#HTTP_1_1} even if the remote peer is
|
||||||
* using {@link Protocol#HTTP_1_0}.
|
* using {@link Protocol#HTTP_1_0}.
|
||||||
*/
|
*/
|
||||||
Protocol getProtocol();
|
Protocol protocol();
|
||||||
}
|
}
|
||||||
|
@@ -32,6 +32,8 @@ import java.util.concurrent.LinkedBlockingQueue;
|
|||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static okhttp3.internal.Util.closeQuietly;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages reuse of HTTP and SPDY connections for reduced network latency. HTTP
|
* Manages reuse of HTTP and SPDY connections for reduced network latency. HTTP
|
||||||
* requests that share the same {@link Address} may share a
|
* requests that share the same {@link Address} may share a
|
||||||
@@ -168,7 +170,7 @@ public final class ConnectionPool {
|
|||||||
// TODO(jwilson): this is awkward. We're already holding a lock on 'this', and
|
// TODO(jwilson): this is awkward. We're already holding a lock on 'this', and
|
||||||
// connection.allocationLimit() may also lock the FramedConnection.
|
// connection.allocationLimit() may also lock the FramedConnection.
|
||||||
if (connection.allocations.size() < connection.allocationLimit()
|
if (connection.allocations.size() < connection.allocationLimit()
|
||||||
&& address.equals(connection.getRoute().address)
|
&& address.equals(connection.route().address)
|
||||||
&& !connection.noNewStreams) {
|
&& !connection.noNewStreams) {
|
||||||
streamAllocation.acquire(connection);
|
streamAllocation.acquire(connection);
|
||||||
return connection;
|
return connection;
|
||||||
@@ -215,7 +217,7 @@ public final class ConnectionPool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (RealConnection connection : evictedConnections) {
|
for (RealConnection connection : evictedConnections) {
|
||||||
Util.closeQuietly(connection.getSocket());
|
closeQuietly(connection.socket());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,7 +275,7 @@ public final class ConnectionPool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Util.closeQuietly(longestIdleConnection.getSocket());
|
closeQuietly(longestIdleConnection.socket());
|
||||||
|
|
||||||
// Cleanup again immediately.
|
// Cleanup again immediately.
|
||||||
return 0;
|
return 0;
|
||||||
@@ -296,7 +298,7 @@ public final class ConnectionPool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We've discovered a leaked allocation. This is an application bug.
|
// We've discovered a leaked allocation. This is an application bug.
|
||||||
Internal.logger.warning("A connection to " + connection.getRoute().address().url()
|
Internal.logger.warning("A connection to " + connection.route().address().url()
|
||||||
+ " was leaked. Did you forget to close a response body?");
|
+ " was leaked. Did you forget to close a response body?");
|
||||||
references.remove(i);
|
references.remove(i);
|
||||||
connection.noNewStreams = true;
|
connection.noNewStreams = true;
|
||||||
|
@@ -119,7 +119,7 @@ public final class Http1xStream implements HttpStream {
|
|||||||
@Override public void writeRequestHeaders(Request request) throws IOException {
|
@Override public void writeRequestHeaders(Request request) throws IOException {
|
||||||
httpEngine.writingRequestHeaders();
|
httpEngine.writingRequestHeaders();
|
||||||
String requestLine = RequestLine.get(
|
String requestLine = RequestLine.get(
|
||||||
request, httpEngine.getConnection().getRoute().proxy().type());
|
request, httpEngine.getConnection().route().proxy().type());
|
||||||
writeRequest(request.headers(), requestLine);
|
writeRequest(request.headers(), requestLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -653,7 +653,7 @@ public final class HttpEngine {
|
|||||||
|
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
Interceptor caller = client.networkInterceptors().get(index - 1);
|
Interceptor caller = client.networkInterceptors().get(index - 1);
|
||||||
Address address = connection().getRoute().address();
|
Address address = connection().route().address();
|
||||||
|
|
||||||
// Confirm that the interceptor uses the connection we've already prepared.
|
// Confirm that the interceptor uses the connection we've already prepared.
|
||||||
if (!request.url().host().equals(address.url().host())
|
if (!request.url().host().equals(address.url().host())
|
||||||
@@ -717,7 +717,7 @@ public final class HttpEngine {
|
|||||||
|
|
||||||
Response networkResponse = httpStream.readResponseHeaders()
|
Response networkResponse = httpStream.readResponseHeaders()
|
||||||
.request(networkRequest)
|
.request(networkRequest)
|
||||||
.handshake(streamAllocation.connection().getHandshake())
|
.handshake(streamAllocation.connection().handshake())
|
||||||
.header(OkHeaders.SENT_MILLIS, Long.toString(sentRequestMillis))
|
.header(OkHeaders.SENT_MILLIS, Long.toString(sentRequestMillis))
|
||||||
.header(OkHeaders.RECEIVED_MILLIS, Long.toString(System.currentTimeMillis()))
|
.header(OkHeaders.RECEIVED_MILLIS, Long.toString(System.currentTimeMillis()))
|
||||||
.build();
|
.build();
|
||||||
@@ -869,7 +869,7 @@ public final class HttpEngine {
|
|||||||
if (userResponse == null) throw new IllegalStateException();
|
if (userResponse == null) throw new IllegalStateException();
|
||||||
Connection connection = streamAllocation.connection();
|
Connection connection = streamAllocation.connection();
|
||||||
Route route = connection != null
|
Route route = connection != null
|
||||||
? connection.getRoute()
|
? connection.route()
|
||||||
: null;
|
: null;
|
||||||
int responseCode = userResponse.code();
|
int responseCode = userResponse.code();
|
||||||
|
|
||||||
|
@@ -101,7 +101,7 @@ public final class StreamAllocation {
|
|||||||
if (resultConnection.framedConnection != null) {
|
if (resultConnection.framedConnection != null) {
|
||||||
resultStream = new Http2xStream(this, resultConnection.framedConnection);
|
resultStream = new Http2xStream(this, resultConnection.framedConnection);
|
||||||
} else {
|
} else {
|
||||||
resultConnection.getSocket().setSoTimeout(readTimeout);
|
resultConnection.socket().setSoTimeout(readTimeout);
|
||||||
resultConnection.source.timeout().timeout(readTimeout, MILLISECONDS);
|
resultConnection.source.timeout().timeout(readTimeout, MILLISECONDS);
|
||||||
resultConnection.sink.timeout().timeout(writeTimeout, MILLISECONDS);
|
resultConnection.sink.timeout().timeout(writeTimeout, MILLISECONDS);
|
||||||
resultStream = new Http1xStream(this, resultConnection.source, resultConnection.sink);
|
resultStream = new Http1xStream(this, resultConnection.source, resultConnection.sink);
|
||||||
@@ -177,7 +177,7 @@ public final class StreamAllocation {
|
|||||||
|
|
||||||
newConnection.connect(connectTimeout, readTimeout, writeTimeout, address.connectionSpecs(),
|
newConnection.connect(connectTimeout, readTimeout, writeTimeout, address.connectionSpecs(),
|
||||||
connectionRetryEnabled);
|
connectionRetryEnabled);
|
||||||
routeDatabase().connected(newConnection.getRoute());
|
routeDatabase().connected(newConnection.route());
|
||||||
|
|
||||||
return newConnection;
|
return newConnection;
|
||||||
}
|
}
|
||||||
@@ -247,7 +247,7 @@ public final class StreamAllocation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (connectionToClose != null) {
|
if (connectionToClose != null) {
|
||||||
Util.closeQuietly(connectionToClose.getSocket());
|
Util.closeQuietly(connectionToClose.socket());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -297,7 +297,7 @@ public final class RealConnection implements Connection {
|
|||||||
return protocol != null;
|
return protocol != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Route getRoute() {
|
@Override public Route route() {
|
||||||
return route;
|
return route;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,7 +306,7 @@ public final class RealConnection implements Connection {
|
|||||||
closeQuietly(rawSocket);
|
closeQuietly(rawSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Socket getSocket() {
|
@Override public Socket socket() {
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,7 +349,7 @@ public final class RealConnection implements Connection {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Handshake getHandshake() {
|
@Override public Handshake handshake() {
|
||||||
return handshake;
|
return handshake;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,7 +361,7 @@ public final class RealConnection implements Connection {
|
|||||||
return framedConnection != null;
|
return framedConnection != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Protocol getProtocol() {
|
@Override public Protocol protocol() {
|
||||||
return protocol != null ? protocol : Protocol.HTTP_1_1;
|
return protocol != null ? protocol : Protocol.HTTP_1_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -31,7 +31,7 @@ public final class CheckHandshake {
|
|||||||
Set<String> blacklist = Collections.singleton("sha1/DmxUShsZuNiqPQsX2Oi9uv2sCnw=");
|
Set<String> blacklist = Collections.singleton("sha1/DmxUShsZuNiqPQsX2Oi9uv2sCnw=");
|
||||||
|
|
||||||
@Override public Response intercept(Chain chain) throws IOException {
|
@Override public Response intercept(Chain chain) throws IOException {
|
||||||
for (Certificate certificate : chain.connection().getHandshake().peerCertificates()) {
|
for (Certificate certificate : chain.connection().handshake().peerCertificates()) {
|
||||||
String pin = CertificatePinner.pin(certificate);
|
String pin = CertificatePinner.pin(certificate);
|
||||||
if (blacklist.contains(pin)) {
|
if (blacklist.contains(pin)) {
|
||||||
throw new IOException("Blacklisted peer certificate: " + pin);
|
throw new IOException("Blacklisted peer certificate: " + pin);
|
||||||
|
Reference in New Issue
Block a user