Skip to content

Commit f721e05

Browse files
committed
Added convenience connector for OkHttp3
Note that the existing one needs to be kept for compatibility with OkHttp2
1 parent e6ad9fe commit f721e05

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@
144144
<version>2.7.5</version>
145145
<optional>true</optional>
146146
</dependency>
147+
<dependency>
148+
<groupId>com.squareup.okhttp3</groupId>
149+
<artifactId>okhttp-urlconnection</artifactId>
150+
<version>3.4.0</version>
151+
<optional>true</optional>
152+
</dependency>
147153
<dependency>
148154
<groupId>org.kohsuke</groupId>
149155
<artifactId>wordnet-random-name</artifactId>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.kohsuke.github.extras;
2+
3+
import okhttp3.OkHttpClient;
4+
import okhttp3.OkUrlFactory;
5+
import org.kohsuke.github.HttpConnector;
6+
7+
import java.io.IOException;
8+
import java.net.HttpURLConnection;
9+
import java.net.URL;
10+
11+
/**
12+
* {@link HttpConnector} for {@link OkHttpClient}.
13+
*
14+
* Unlike {@link #DEFAULT}, OkHttp does response caching.
15+
* Making a conditional request against GitHubAPI and receiving a 304
16+
* response does not count against the rate limit.
17+
* See http://developer.github.com/v3/#conditional-requests
18+
*
19+
* @author Roberto Tyley
20+
* @author Kohsuke Kawaguchi
21+
*/
22+
public class OkHttp3Connector implements HttpConnector {
23+
private final OkUrlFactory urlFactory;
24+
25+
public OkHttp3Connector(OkUrlFactory urlFactory) {
26+
this.urlFactory = urlFactory;
27+
}
28+
29+
public HttpURLConnection connect(URL url) throws IOException {
30+
return urlFactory.open(url);
31+
}
32+
}

0 commit comments

Comments
 (0)