OkHttpClientHttpRequestFactory allows POST request without body
Issue: SPR-15015
This commit is contained in:
@@ -19,7 +19,6 @@ package org.springframework.http.client;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -73,7 +72,7 @@ public class OkHttp3ClientHttpRequestFactory
|
||||
/**
|
||||
* Sets the underlying read timeout in milliseconds.
|
||||
* A value of 0 specifies an infinite timeout.
|
||||
* @see okhttp3.OkHttpClient.Builder#readTimeout(long, TimeUnit)
|
||||
* @see OkHttpClient.Builder#readTimeout(long, TimeUnit)
|
||||
*/
|
||||
public void setReadTimeout(int readTimeout) {
|
||||
this.client = this.client.newBuilder()
|
||||
@@ -84,7 +83,7 @@ public class OkHttp3ClientHttpRequestFactory
|
||||
/**
|
||||
* Sets the underlying write timeout in milliseconds.
|
||||
* A value of 0 specifies an infinite timeout.
|
||||
* @see okhttp3.OkHttpClient.Builder#writeTimeout(long, TimeUnit)
|
||||
* @see OkHttpClient.Builder#writeTimeout(long, TimeUnit)
|
||||
*/
|
||||
public void setWriteTimeout(int writeTimeout) {
|
||||
this.client = this.client.newBuilder()
|
||||
@@ -95,7 +94,7 @@ public class OkHttp3ClientHttpRequestFactory
|
||||
/**
|
||||
* Sets the underlying connect timeout in milliseconds.
|
||||
* A value of 0 specifies an infinite timeout.
|
||||
* @see okhttp3.OkHttpClient.Builder#connectTimeout(long, TimeUnit)
|
||||
* @see OkHttpClient.Builder#connectTimeout(long, TimeUnit)
|
||||
*/
|
||||
public void setConnectTimeout(int connectTimeout) {
|
||||
this.client = this.client.newBuilder()
|
||||
@@ -127,23 +126,21 @@ public class OkHttp3ClientHttpRequestFactory
|
||||
}
|
||||
|
||||
|
||||
static Request buildRequest(HttpHeaders headers, byte[] content, URI uri,
|
||||
HttpMethod method) throws MalformedURLException {
|
||||
static Request buildRequest(HttpHeaders headers, byte[] content, URI uri, HttpMethod method)
|
||||
throws MalformedURLException {
|
||||
|
||||
okhttp3.MediaType contentType = getContentType(headers);
|
||||
RequestBody body = (content.length > 0 ? RequestBody.create(contentType, content) : null);
|
||||
|
||||
URL url = uri.toURL();
|
||||
String methodName = method.name();
|
||||
Request.Builder builder = new Request.Builder().url(url).method(methodName, body);
|
||||
RequestBody body = (content.length > 0 ||
|
||||
okhttp3.internal.http.HttpMethod.requiresRequestBody(method.name()) ?
|
||||
RequestBody.create(contentType, content) : null);
|
||||
|
||||
Request.Builder builder = new Request.Builder().url(uri.toURL()).method(method.name(), body);
|
||||
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
|
||||
String headerName = entry.getKey();
|
||||
for (String headerValue : entry.getValue()) {
|
||||
builder.addHeader(headerName, headerValue);
|
||||
}
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.http.client;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -123,23 +122,21 @@ public class OkHttpClientHttpRequestFactory
|
||||
}
|
||||
|
||||
|
||||
static Request buildRequest(HttpHeaders headers, byte[] content, URI uri,
|
||||
HttpMethod method) throws MalformedURLException {
|
||||
static Request buildRequest(HttpHeaders headers, byte[] content, URI uri, HttpMethod method)
|
||||
throws MalformedURLException {
|
||||
|
||||
com.squareup.okhttp.MediaType contentType = getContentType(headers);
|
||||
RequestBody body = (content.length > 0 ? RequestBody.create(contentType, content) : null);
|
||||
|
||||
URL url = uri.toURL();
|
||||
String methodName = method.name();
|
||||
Request.Builder builder = new Request.Builder().url(url).method(methodName, body);
|
||||
RequestBody body = (content.length > 0 ||
|
||||
com.squareup.okhttp.internal.http.HttpMethod.requiresRequestBody(method.name()) ?
|
||||
RequestBody.create(contentType, content) : null);
|
||||
|
||||
Request.Builder builder = new Request.Builder().url(uri.toURL()).method(method.name(), body);
|
||||
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
|
||||
String headerName = entry.getKey();
|
||||
for (String headerValue : entry.getValue()) {
|
||||
builder.addHeader(headerName, headerValue);
|
||||
}
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user