Created
May 21, 2013 01:14
-
-
Save JakeWharton/5616899 to your computer and use it in GitHub Desktop.
A `HttpStack` implementation for Volley that uses OkHttp as its transport.
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
import com.android.volley.toolbox.HurlStack; | |
import com.squareup.okhttp.OkHttpClient; | |
import java.io.IOException; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
/** | |
* An {@link com.android.volley.toolbox.HttpStack HttpStack} implementation which | |
* uses OkHttp as its transport. | |
*/ | |
public class OkHttpStack extends HurlStack { | |
private final OkHttpClient client; | |
public OkHttpStack() { | |
this(new OkHttpClient()); | |
} | |
public OkHttpStack(OkHttpClient client) { | |
if (client == null) { | |
throw new NullPointerException("Client must not be null."); | |
} | |
this.client = client; | |
} | |
@Override protected HttpURLConnection createConnection(URL url) throws IOException { | |
return client.open(url); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you guys for the insight, here the updated version using volley 1.2.1 (latest) https://gist.github.com/4sskick/d1318379500747564d8f1c8d6af1f796 in case still you guys still has old project which need to maintain but don't want to refactor to OkHttp or another request library