Created
June 17, 2013 15:04
-
-
Save JakeWharton/5797571 to your computer and use it in GitHub Desktop.
A connection factory for using OkHttp with Kevin Sawicki's HttpRequest library.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A {@link HttpRequest.ConnectionFactory connection factory} which uses OkHttp. | |
* <p/> | |
* Call {@link HttpRequest#setConnectionFactory(HttpRequest.ConnectionFactory)} with an instance of | |
* this class to enable. | |
*/ | |
public class OkConnectionFactory implements HttpRequest.ConnectionFactory { | |
private final OkHttpClient client; | |
public OkConnectionFactory() { | |
this(new OkHttpClient()); | |
} | |
public OkConnectionFactory(OkHttpClient client) { | |
if (client == null) { | |
throw new NullPointerException("Client must not be null."); | |
} | |
this.client = client; | |
} | |
public HttpURLConnection create(URL url) throws IOException { | |
return client.open(url); | |
} | |
public HttpURLConnection create(URL url, Proxy proxy) throws IOException { | |
throw new UnsupportedOperationException( | |
"Per-connection proxy is not supported. Use OkHttpClient's setProxy instead."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@rockerhieu I can't import the OkUrlFactory class, where i can find it? By the way i using the okhttp 2.1.0.
thanks!