mirror of
https://github.com/square/okhttp.git
synced 2026-01-25 16:01:38 +03:00
Merge branch 'master' of https://github.com/square/okhttp
This commit is contained in:
26
README.md
26
README.md
@@ -1,13 +1,16 @@
|
||||
OkHttp
|
||||
======
|
||||
|
||||
An HTTP+SPDY client for Android and Java applications.
|
||||
An HTTP & SPDY client for Android and Java applications.
|
||||
|
||||
For more information please see [the website][1].
|
||||
|
||||
|
||||
|
||||
Download
|
||||
--------
|
||||
|
||||
Download [the latest JAR][1] or grab via Maven:
|
||||
Download [the latest JAR][2] or grab via Maven:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
@@ -18,18 +21,6 @@ Download [the latest JAR][1] or grab via Maven:
|
||||
```
|
||||
|
||||
|
||||
Known Issues
|
||||
------------
|
||||
|
||||
OkHttp uses the platform's [ProxySelector][2]. Prior to Android 4.0, `ProxySelector` didn't honor
|
||||
the `proxyHost` and `proxyPort` system properties for HTTPS connections. Work around this by
|
||||
specifying the `https.proxyHost` and `https.proxyPort` system properties when using a proxy with
|
||||
HTTPS.
|
||||
|
||||
OkHttp's test suite creates an in-process HTTPS server. Prior to Android 2.3, SSL server sockets
|
||||
were broken, and so HTTPS tests will time out when run on such devices.
|
||||
|
||||
|
||||
Building
|
||||
--------
|
||||
|
||||
@@ -44,6 +35,9 @@ mvn clean test
|
||||
|
||||
### On a Device
|
||||
|
||||
OkHttp's test suite creates an in-process HTTPS server. Prior to Android 2.3, SSL server sockets
|
||||
were broken, and so HTTPS tests will time out when run on such devices.
|
||||
|
||||
Test on a USB-attached Android using [Vogar][4]. Unfortunately `dx` requires that you build with
|
||||
Java 6, otherwise the test class will be silently omitted from the `.dex` file.
|
||||
|
||||
@@ -76,7 +70,7 @@ License
|
||||
|
||||
|
||||
|
||||
[1]: http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.squareup.okhttp&a=okhttp&v=LATEST
|
||||
[2]: http://developer.android.com/reference/java/net/ProxySelector.html
|
||||
[1]: http://square.github.io/okhttp
|
||||
[2]: http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.squareup.okhttp&a=okhttp&v=LATEST
|
||||
[3]: http://wiki.eclipse.org/Jetty/Feature/NPN
|
||||
[4]: https://code.google.com/p/vogar/
|
||||
|
||||
@@ -23,5 +23,16 @@
|
||||
<artifactId>httpclient</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.mockwebserver</groupId>
|
||||
<artifactId>mockwebserver</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.squareup.okhttp.apache;
|
||||
|
||||
import com.google.mockwebserver.MockResponse;
|
||||
import com.google.mockwebserver.MockWebServer;
|
||||
import java.io.IOException;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class OkApacheClientTest {
|
||||
private MockWebServer server = new MockWebServer();
|
||||
private OkApacheClient client = new OkApacheClient();
|
||||
|
||||
@After public void tearDown() throws IOException {
|
||||
server.shutdown();
|
||||
}
|
||||
|
||||
@Test public void success() throws Exception {
|
||||
server.enqueue(new MockResponse().setBody("Hello, World!"));
|
||||
server.play();
|
||||
|
||||
HttpGet request = new HttpGet(server.getUrl("/").toURI());
|
||||
HttpResponse response = client.execute(request);
|
||||
String actual = EntityUtils.toString(response.getEntity());
|
||||
assertEquals("Hello, World!", actual);
|
||||
}
|
||||
|
||||
@Test public void redirect() throws Exception {
|
||||
server.enqueue(new MockResponse().setResponseCode(302).addHeader("Location", "/foo"));
|
||||
server.enqueue(new MockResponse().setBody("Hello, Redirect!"));
|
||||
server.play();
|
||||
|
||||
HttpGet request = new HttpGet(server.getUrl("/").toURI());
|
||||
HttpResponse response = client.execute(request);
|
||||
String actual = EntityUtils.toString(response.getEntity());
|
||||
assertEquals("Hello, Redirect!", actual);
|
||||
}
|
||||
|
||||
@Test public void sessionExpired() throws Exception {
|
||||
server.enqueue(new MockResponse().setResponseCode(422));
|
||||
server.play();
|
||||
|
||||
HttpGet request = new HttpGet(server.getUrl("/").toURI());
|
||||
HttpResponse response = client.execute(request);
|
||||
assertEquals(422, response.getStatusLine().getStatusCode());
|
||||
}
|
||||
|
||||
@Test public void headers() throws Exception {
|
||||
server.enqueue(new MockResponse().addHeader("Foo", "Bar"));
|
||||
server.enqueue(new MockResponse().addHeader("Foo", "Bar").addHeader("Foo", "Baz"));
|
||||
server.play();
|
||||
|
||||
HttpGet request1 = new HttpGet(server.getUrl("/").toURI());
|
||||
HttpResponse response1 = client.execute(request1);
|
||||
Header[] headers1 = response1.getHeaders("Foo");
|
||||
assertEquals(1, headers1.length);
|
||||
assertEquals("Bar", headers1[0].getValue());
|
||||
|
||||
HttpGet request2 = new HttpGet(server.getUrl("/").toURI());
|
||||
HttpResponse response2 = client.execute(request2);
|
||||
Header[] headers2 = response2.getHeaders("Foo");
|
||||
assertEquals(2, headers2.length);
|
||||
assertEquals("Bar", headers2[0].getValue());
|
||||
assertEquals("Baz", headers2[1].getValue());
|
||||
}
|
||||
}
|
||||
8
pom.xml
8
pom.xml
@@ -146,6 +146,14 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.9</version>
|
||||
<configuration>
|
||||
<excludePackageNames>com.squareup.okhttp.internal:com.squareup.okhttp.internal.*</excludePackageNames>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
Reference in New Issue
Block a user