Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/square/okhttp
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeWharton committed May 7, 2013
2 parents 570385f + 8cb0fc7 commit 8bf24a5
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 16 deletions.
26 changes: 10 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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
--------

Expand All @@ -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.

Expand Down Expand Up @@ -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/
11 changes: 11 additions & 0 deletions okhttp-apache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 8bf24a5

Please sign in to comment.