X Tutup
Skip to content

Commit bd9a430

Browse files
committed
add body for PATCH HTTP method
1 parent ad79556 commit bd9a430

File tree

8 files changed

+20
-11
lines changed

8 files changed

+20
-11
lines changed

changelog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[SNAPSHOT]
2+
* add body for PATCH HTTP method
3+
14
[4.0.0]
25
* Remove OAuthRequestAsync, just OAuthRequest. Request should know about sync vs async. Move default Http engine to JDKHttpClient.
36
* introduce SignatureType for OAuth2.0 to implement Bearer signing for the requests

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
<plugins>
149149
<plugin>
150150
<artifactId>maven-compiler-plugin</artifactId>
151-
<version>3.6.0</version>
151+
<version>3.6.1</version>
152152
<configuration>
153153
<encoding>UTF-8</encoding>
154154
<source>1.7</source>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private Response doExecute(String userAgent, Map<String, String> headers, Verb h
9696
connection.setReadTimeout(config.getReadTimeout());
9797
}
9898
addHeaders(connection, headers, userAgent);
99-
if (httpVerb == Verb.POST || httpVerb == Verb.PUT || httpVerb == Verb.DELETE) {
99+
if (httpVerb.isPermitBody()) {
100100
bodyType.setBody(connection, bodyContents);
101101
}
102102

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,13 @@ public void addQuerystringParameter(String key, String value) {
117117
}
118118

119119
public void addParameter(String key, String value) {
120-
if (hasBodyContent()) {
120+
if (verb.isPermitBody()) {
121121
bodyParams.add(key, value);
122122
} else {
123123
querystringParams.add(key, value);
124124
}
125125
}
126126

127-
protected boolean hasBodyContent() {
128-
return verb == Verb.PUT || verb == Verb.POST;
129-
}
130-
131127
/**
132128
* Set body payload. This method is used when the HTTP body is not a form-url-encoded string, but another thing.
133129
* Like for example XML. Note: The contents are not part of the OAuth signature

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,15 @@
55
*/
66
public enum Verb {
77

8-
GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, PATCH
8+
GET(false), POST(true), PUT(true), DELETE(true), HEAD(false), OPTIONS(false), TRACE(false), PATCH(true);
9+
10+
private final boolean permitBody;
11+
12+
Verb(boolean permitBody) {
13+
this.permitBody = permitBody;
14+
}
15+
16+
public boolean isPermitBody() {
17+
return permitBody;
18+
}
919
}

scribejava-httpclient-ahc/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<dependency>
2424
<groupId>org.asynchttpclient</groupId>
2525
<artifactId>async-http-client</artifactId>
26-
<version>2.0.24</version>
26+
<version>2.0.26</version>
2727
</dependency>
2828
</dependencies>
2929

scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private <T> Future<T> doExecuteAsync(String userAgent, Map<String, String> heade
7676
throw new IllegalArgumentException("message build error: unknown verb type");
7777
}
7878

79-
if (httpVerb == Verb.POST || httpVerb == Verb.PUT || httpVerb == Verb.DELETE) {
79+
if (httpVerb.isPermitBody()) {
8080
if (!headers.containsKey(CONTENT_TYPE)) {
8181
boundRequestBuilder = boundRequestBuilder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE);
8282
}

scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private <T> Future<T> doExecuteAsync(String userAgent, Map<String, String> heade
8484
throw new IllegalArgumentException("message build error: unknown verb type");
8585
}
8686

87-
if (httpVerb == Verb.POST || httpVerb == Verb.PUT || httpVerb == Verb.DELETE) {
87+
if (httpVerb.isPermitBody()) {
8888
if (!headers.containsKey(CONTENT_TYPE)) {
8989
boundRequestBuilder = boundRequestBuilder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE);
9090
}

0 commit comments

Comments
 (0)
X Tutup