Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncomment more HTTPS tests. #11

Merged
merged 1 commit into from
Aug 1, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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