1
0
mirror of https://github.com/square/okhttp.git synced 2026-01-12 10:23:16 +03:00

Move HttpUrlConnection implementation to its own package.

This commit is contained in:
Jake Wharton
2014-04-19 23:53:57 -07:00
parent 6486179b9d
commit 996e9c95bd
17 changed files with 49 additions and 38 deletions

View File

@@ -16,7 +16,6 @@
package com.squareup.okhttp.benchmarks;
import com.squareup.okhttp.internal.SslContextBuilder;
import com.squareup.okhttp.internal.http.HttpsURLConnectionImpl;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
@@ -24,6 +23,7 @@ import java.net.URL;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
@@ -41,8 +41,8 @@ class UrlConnection extends SynchronousHttpClient {
return true;
}
};
HttpsURLConnectionImpl.setDefaultHostnameVerifier(hostnameVerifier);
HttpsURLConnectionImpl.setDefaultSSLSocketFactory(socketFactory);
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
HttpsURLConnection.setDefaultSSLSocketFactory(socketFactory);
}
}

View File

@@ -56,7 +56,9 @@
<module name="IllegalImport"/>
<!-- defaults to sun.* packages -->
<module name="RedundantImport"/>
<module name="UnusedImports"/>
<module name="UnusedImports">
<property name="processJavadoc" value="true"/>
</module>
<!-- Checks for Size Violations. -->

View File

@@ -37,6 +37,7 @@ import java.util.List;
import java.util.NoSuchElementException;
import javax.net.SocketFactory;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLSocketFactory;
@@ -74,7 +75,7 @@ public final class RouteSelectorTest {
uri = new URI("http://" + uriHost + ":" + uriPort + "/path");
socketFactory = SocketFactory.getDefault();
pool = ConnectionPool.getDefault();
hostnameVerifier = HttpsURLConnectionImpl.getDefaultHostnameVerifier();
hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
} catch (Exception e) {
throw new AssertionError(e);
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.squareup.okhttp.internal.http;
package com.squareup.okhttp.internal.huc;
import com.squareup.okhttp.ConnectionPool;
import com.squareup.okhttp.HttpResponseCache;
@@ -25,6 +25,7 @@ import com.squareup.okhttp.Response;
import com.squareup.okhttp.ResponseSource;
import com.squareup.okhttp.internal.SslContextBuilder;
import com.squareup.okhttp.internal.Util;
import com.squareup.okhttp.internal.http.OkHeaders;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import com.squareup.okhttp.mockwebserver.RecordedRequest;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.squareup.okhttp.internal.http;
package com.squareup.okhttp.internal.huc;
import com.squareup.okhttp.Handshake;
import com.squareup.okhttp.Headers;

View File

@@ -13,17 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.okhttp.internal.http;
package com.squareup.okhttp.internal.huc;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.internal.SslContextBuilder;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import java.net.CacheRequest;
import java.net.CacheResponse;
@@ -36,17 +31,17 @@ import java.net.URLConnection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

View File

@@ -14,11 +14,12 @@
* limitations under the License.
*/
package com.squareup.okhttp.internal.http;
package com.squareup.okhttp.internal.huc;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.ResponseSource;
import com.squareup.okhttp.internal.SslContextBuilder;
import com.squareup.okhttp.internal.http.OkHeaders;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import com.squareup.okhttp.mockwebserver.RecordedRequest;
@@ -80,7 +81,7 @@ import static org.junit.Assert.fail;
/**
* Tests for interaction between OkHttp and the ResponseCache. This test is based on
* {@link com.squareup.okhttp.internal.http.HttpResponseCacheTest}. Some tests for the
* {@link HttpResponseCacheTest}. Some tests for the
* {@link com.squareup.okhttp.OkResponseCache} found in HttpResponseCacheTest provide
* coverage for ResponseCache as well.
*/

View File

@@ -19,9 +19,9 @@ package com.squareup.okhttp;
import com.squareup.okhttp.internal.DiskLruCache;
import com.squareup.okhttp.internal.Util;
import com.squareup.okhttp.internal.http.HttpMethod;
import com.squareup.okhttp.internal.http.HttpURLConnectionImpl;
import com.squareup.okhttp.internal.http.HttpsURLConnectionImpl;
import com.squareup.okhttp.internal.http.JavaApiConverter;
import com.squareup.okhttp.internal.huc.HttpURLConnectionImpl;
import com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl;
import com.squareup.okhttp.internal.huc.JavaApiConverter;
import com.squareup.okhttp.internal.http.OkHeaders;
import com.squareup.okhttp.internal.http.StatusLine;
import java.io.BufferedWriter;

View File

@@ -18,8 +18,8 @@ package com.squareup.okhttp;
import com.squareup.okhttp.internal.NamedRunnable;
import com.squareup.okhttp.internal.http.HttpAuthenticator;
import com.squareup.okhttp.internal.http.HttpEngine;
import com.squareup.okhttp.internal.http.HttpURLConnectionImpl;
import com.squareup.okhttp.internal.http.OkHeaders;
import com.squareup.okhttp.internal.huc.HttpURLConnectionImpl;
import java.io.IOException;
import java.net.ProtocolException;
import java.net.Proxy;
@@ -29,13 +29,13 @@ import okio.BufferedSource;
import okio.Okio;
import static com.squareup.okhttp.internal.Util.getEffectivePort;
import static com.squareup.okhttp.internal.http.HttpURLConnectionImpl.HTTP_MOVED_PERM;
import static com.squareup.okhttp.internal.http.HttpURLConnectionImpl.HTTP_MOVED_TEMP;
import static com.squareup.okhttp.internal.http.HttpURLConnectionImpl.HTTP_MULT_CHOICE;
import static com.squareup.okhttp.internal.http.HttpURLConnectionImpl.HTTP_PROXY_AUTH;
import static com.squareup.okhttp.internal.http.HttpURLConnectionImpl.HTTP_SEE_OTHER;
import static com.squareup.okhttp.internal.http.HttpURLConnectionImpl.HTTP_UNAUTHORIZED;
import static com.squareup.okhttp.internal.http.StatusLine.HTTP_TEMP_REDIRECT;
import static java.net.HttpURLConnection.HTTP_MOVED_PERM;
import static java.net.HttpURLConnection.HTTP_MOVED_TEMP;
import static java.net.HttpURLConnection.HTTP_MULT_CHOICE;
import static java.net.HttpURLConnection.HTTP_PROXY_AUTH;
import static java.net.HttpURLConnection.HTTP_SEE_OTHER;
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
final class Job extends NamedRunnable {
private final Dispatcher dispatcher;

View File

@@ -17,9 +17,9 @@ package com.squareup.okhttp;
import com.squareup.okhttp.internal.Util;
import com.squareup.okhttp.internal.http.HttpAuthenticator;
import com.squareup.okhttp.internal.http.HttpURLConnectionImpl;
import com.squareup.okhttp.internal.http.HttpsURLConnectionImpl;
import com.squareup.okhttp.internal.http.ResponseCacheAdapter;
import com.squareup.okhttp.internal.huc.HttpURLConnectionImpl;
import com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl;
import com.squareup.okhttp.internal.huc.ResponseCacheAdapter;
import com.squareup.okhttp.internal.tls.OkHostnameVerifier;
import java.io.IOException;
import java.net.CookieHandler;

View File

@@ -2,6 +2,7 @@ package com.squareup.okhttp.internal.http;
import com.squareup.okhttp.Protocol;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.internal.huc.HttpURLConnectionImpl;
import java.net.Proxy;
import java.net.URL;

View File

@@ -30,7 +30,7 @@ import static com.squareup.okhttp.internal.Util.checkOffsetAndCount;
* the post body to be transparently re-sent if the HTTP request must be
* sent multiple times.
*/
final class RetryableSink implements Sink {
public final class RetryableSink implements Sink {
private boolean closed;
private final int limit;
private final Buffer content = new Buffer();

View File

@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.okhttp.internal.http;
package com.squareup.okhttp.internal.huc;
import com.squareup.okhttp.Handshake;
import java.io.IOException;

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.squareup.okhttp.internal.http;
package com.squareup.okhttp.internal.huc;
import com.squareup.okhttp.Connection;
import com.squareup.okhttp.Handshake;
@@ -27,6 +27,13 @@ import com.squareup.okhttp.Response;
import com.squareup.okhttp.Route;
import com.squareup.okhttp.internal.Platform;
import com.squareup.okhttp.internal.Util;
import com.squareup.okhttp.internal.http.HttpAuthenticator;
import com.squareup.okhttp.internal.http.HttpDate;
import com.squareup.okhttp.internal.http.HttpEngine;
import com.squareup.okhttp.internal.http.HttpMethod;
import com.squareup.okhttp.internal.http.OkHeaders;
import com.squareup.okhttp.internal.http.RetryableSink;
import com.squareup.okhttp.internal.http.StatusLine;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -69,6 +76,7 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
* How many redirects should we follow? Chrome follows 21; Firefox, curl,
* and wget follow 20; Safari follows 16; and HTTP/1.0 recommends 5.
*/
// TODO find a better location for this constant
public static final int MAX_REDIRECTS = 20;
final OkHttpClient client;

View File

@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.okhttp.internal.http;
package com.squareup.okhttp.internal.huc;
import com.squareup.okhttp.Handshake;
import com.squareup.okhttp.OkHttpClient;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.okhttp.internal.http;
package com.squareup.okhttp.internal.huc;
import com.squareup.okhttp.Handshake;
import com.squareup.okhttp.Headers;
@@ -22,6 +22,8 @@ import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.ResponseSource;
import com.squareup.okhttp.internal.Util;
import com.squareup.okhttp.internal.http.OkHeaders;
import com.squareup.okhttp.internal.http.StatusLine;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.okhttp.internal.http;
package com.squareup.okhttp.internal.huc;
import com.squareup.okhttp.OkResponseCache;
import com.squareup.okhttp.Request;
@@ -29,7 +29,7 @@ import java.util.List;
import java.util.Map;
/** Adapts {@link ResponseCache} to {@link OkResponseCache}. */
public class ResponseCacheAdapter implements OkResponseCache {
public final class ResponseCacheAdapter implements OkResponseCache {
private final ResponseCache delegate;