Skip to content

Commit a75a695

Browse files
committed
move JDK HTTP client specific config (followRedirects) from OAuthRequest to JDKHttpClientConfig
1 parent 8dc7883 commit a75a695

3 files changed

Lines changed: 22 additions & 22 deletions

File tree

scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class JDKHttpClientConfig implements HttpClientConfig {
66

77
private Integer connectTimeout;
88
private Integer readTimeout;
9+
private boolean followRedirects = true;
910

1011
@Override
1112
public JDKHttpClientConfig createDefaultConfig() {
@@ -31,4 +32,21 @@ public Integer getReadTimeout() {
3132
public void setReadTimeout(Integer readTimeout) {
3233
this.readTimeout = readTimeout;
3334
}
35+
36+
public boolean isFollowRedirects() {
37+
return followRedirects;
38+
}
39+
40+
/**
41+
* Sets whether the underlying Http Connection follows redirects or not.
42+
*
43+
* Defaults to true (follow redirects)
44+
*
45+
* @see <a
46+
* href="http://docs.oracle.com/javase/6/docs/api/java/net/HttpURLConnection.html#setInstanceFollowRedirects(boolean)">http://docs.oracle.com/javase/6/docs/api/java/net/HttpURLConnection.html#setInstanceFollowRedirects(boolean)</a>
47+
* @param followRedirects boolean
48+
*/
49+
public void setFollowRedirects(boolean followRedirects) {
50+
this.followRedirects = followRedirects;
51+
}
3452
}

scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public abstract class AbstractRequest {
2424
private final ParameterList querystringParams = new ParameterList();
2525
private final ParameterList bodyParams = new ParameterList();
2626
private final Map<String, String> headers = new HashMap<>();
27-
private boolean followRedirects = true;
2827

2928
private String charset;
3029

@@ -275,21 +274,4 @@ public String getCharset() {
275274
public void setCharset(String charsetName) {
276275
charset = charsetName;
277276
}
278-
279-
/**
280-
* Sets whether the underlying Http Connection follows redirects or not.
281-
*
282-
* Defaults to true (follow redirects)
283-
*
284-
* @see <a
285-
* href="http://docs.oracle.com/javase/6/docs/api/java/net/HttpURLConnection.html#setInstanceFollowRedirects(boolean)">http://docs.oracle.com/javase/6/docs/api/java/net/HttpURLConnection.html#setInstanceFollowRedirects(boolean)</a>
286-
* @param followRedirects boolean
287-
*/
288-
public void setFollowRedirects(boolean followRedirects) {
289-
this.followRedirects = followRedirects;
290-
}
291-
292-
public boolean isFollowRedirects() {
293-
return followRedirects;
294-
}
295277
}

scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ public OAuthRequest(Verb verb, String url, OAuthConfig config) {
3232

3333
public Response send(String userAgent, JDKHttpClientConfig httpClientConfig) {
3434
try {
35-
return doSend(userAgent, httpClientConfig, isFollowRedirects(), getHeaders(), getVerb(), getCompleteUrl(),
35+
return doSend(userAgent, httpClientConfig, getHeaders(), getVerb(), getCompleteUrl(),
3636
this);
3737
} catch (IOException | RuntimeException e) {
3838
throw new OAuthConnectionException(getCompleteUrl(), e);
3939
}
4040
}
4141

42-
private static Response doSend(String userAgent, JDKHttpClientConfig httpClientConfig, boolean followRedirects,
43-
Map<String, String> headers, Verb httpVerb, String completeUrl, OAuthRequest request) throws IOException {
42+
private static Response doSend(String userAgent, JDKHttpClientConfig httpClientConfig, Map<String, String> headers,
43+
Verb httpVerb, String completeUrl, OAuthRequest request) throws IOException {
4444
final HttpURLConnection connection = (HttpURLConnection) new URL(completeUrl).openConnection();
45-
connection.setInstanceFollowRedirects(followRedirects);
45+
connection.setInstanceFollowRedirects(httpClientConfig.isFollowRedirects());
4646
connection.setRequestMethod(httpVerb.name());
4747
if (httpClientConfig.getConnectTimeout() != null) {
4848
connection.setConnectTimeout(httpClientConfig.getConnectTimeout());

0 commit comments

Comments
 (0)