Skip to content

Commit

Permalink
Merge pull request #11 from square/jwilson/tests
Browse files Browse the repository at this point in the history
Uncomment more HTTPS tests.
  • Loading branch information
edenman committed Aug 1, 2012
2 parents 54439c2 + 3ff6ca1 commit cb31fab
Show file tree
Hide file tree
Showing 5 changed files with 330 additions and 300 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<!-- Compilation -->
<java.version>1.6</java.version>
<npn.version>8.1.2.v20120308</npn.version>
<mockwebserver.version>20120401</mockwebserver.version>
<mockwebserver.version>20120731</mockwebserver.version>
<bouncycastle.version>1.47</bouncycastle.version>

<!-- Test Dependencies -->
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/com/squareup/okhttp/OkHttpConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,33 @@ public abstract class OkHttpConnection extends URLConnection {
*/
public static final int HTTP_VERSION = 505;

/**
* Returns a new OkHttpConnection or OkHttpsConnection to {@code url}.
*/
public static OkHttpConnection open(URL url) {
return new libcore.net.http.HttpURLConnectionImpl(url, 443);
String protocol = url.getProtocol();
if (protocol.equals("http")) {
return new libcore.net.http.HttpURLConnectionImpl(url, 80);
} else if (protocol.equals("https")) {
return new libcore.net.http.HttpsURLConnectionImpl(url, 443);
} else {
throw new IllegalArgumentException();
}
}

/**
* Returns a new OkHttpConnection or OkHttpsConnection to {@code url} that
* connects via {@code proxy}.
*/
public static OkHttpConnection open(URL url, Proxy proxy) {
return new libcore.net.http.HttpURLConnectionImpl(url, 443, proxy);
String protocol = url.getProtocol();
if (protocol.equals("http")) {
return new libcore.net.http.HttpURLConnectionImpl(url, 80, proxy);
} else if (protocol.equals("https")) {
return new libcore.net.http.HttpsURLConnectionImpl(url, 443, proxy);
} else {
throw new IllegalArgumentException();
}
}

/**
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/com/squareup/okhttp/OkHttpsConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package com.squareup.okhttp;

import java.net.Proxy;
import java.net.URL;
import java.security.Principal;
import java.security.cert.Certificate;
Expand Down Expand Up @@ -113,14 +112,6 @@ public abstract class OkHttpsConnection extends OkHttpConnection {
private static SSLSocketFactory defaultSSLSocketFactory = (SSLSocketFactory) SSLSocketFactory
.getDefault();

public static OkHttpsConnection open(URL url) {
return new libcore.net.http.HttpsURLConnectionImpl(url, 443);
}

public static OkHttpsConnection open(URL url, Proxy proxy) {
return new libcore.net.http.HttpsURLConnectionImpl(url, 443, proxy);
}

/**
* Sets the default hostname verifier to be used by new instances.
*
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/libcore/net/http/ExternalSpdyExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package libcore.net.http;

import com.squareup.okhttp.OkHttpConnection;
import com.squareup.okhttp.OkHttpsConnection;
import java.io.BufferedReader;
import java.io.InputStreamReader;
Expand All @@ -26,7 +27,7 @@
public final class ExternalSpdyExample {
public static void main(String[] args) throws Exception {
URL url = new URL("https://www.google.ca/");
OkHttpsConnection connection = OkHttpsConnection.open(url);
OkHttpsConnection connection = (OkHttpsConnection) OkHttpConnection.open(url);

connection.setHostnameVerifier(new HostnameVerifier() {
@Override public boolean verify(String s, SSLSession sslSession) {
Expand Down
Loading

0 comments on commit cb31fab

Please sign in to comment.