|
@@ -20,6 +20,7 @@
|
|
|
package org.elasticsearch.client;
|
|
|
|
|
|
import org.apache.http.Header;
|
|
|
+import org.apache.http.client.config.RequestConfig;
|
|
|
import org.apache.http.message.BasicHeader;
|
|
|
import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
|
|
|
import org.elasticsearch.client.HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory;
|
|
@@ -38,23 +39,25 @@ public final class RequestOptions {
|
|
|
* Default request options.
|
|
|
*/
|
|
|
public static final RequestOptions DEFAULT = new Builder(
|
|
|
- Collections.emptyList(), HeapBufferedResponseConsumerFactory.DEFAULT, null).build();
|
|
|
+ Collections.emptyList(), HeapBufferedResponseConsumerFactory.DEFAULT, null, null).build();
|
|
|
|
|
|
private final List<Header> headers;
|
|
|
private final HttpAsyncResponseConsumerFactory httpAsyncResponseConsumerFactory;
|
|
|
private final WarningsHandler warningsHandler;
|
|
|
+ private final RequestConfig requestConfig;
|
|
|
|
|
|
private RequestOptions(Builder builder) {
|
|
|
this.headers = Collections.unmodifiableList(new ArrayList<>(builder.headers));
|
|
|
this.httpAsyncResponseConsumerFactory = builder.httpAsyncResponseConsumerFactory;
|
|
|
this.warningsHandler = builder.warningsHandler;
|
|
|
+ this.requestConfig = builder.requestConfig;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Create a builder that contains these options but can be modified.
|
|
|
*/
|
|
|
public Builder toBuilder() {
|
|
|
- return new Builder(headers, httpAsyncResponseConsumerFactory, warningsHandler);
|
|
|
+ return new Builder(headers, httpAsyncResponseConsumerFactory, warningsHandler, requestConfig);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -95,6 +98,15 @@ public final class RequestOptions {
|
|
|
return warningsHandler;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * get RequestConfig, which can set socketTimeout, connectTimeout
|
|
|
+ * and so on by request
|
|
|
+ * @return RequestConfig
|
|
|
+ */
|
|
|
+ public RequestConfig getRequestConfig() {
|
|
|
+ return requestConfig;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public String toString() {
|
|
|
StringBuilder b = new StringBuilder();
|
|
@@ -152,12 +164,14 @@ public final class RequestOptions {
|
|
|
private final List<Header> headers;
|
|
|
private HttpAsyncResponseConsumerFactory httpAsyncResponseConsumerFactory;
|
|
|
private WarningsHandler warningsHandler;
|
|
|
+ private RequestConfig requestConfig;
|
|
|
|
|
|
private Builder(List<Header> headers, HttpAsyncResponseConsumerFactory httpAsyncResponseConsumerFactory,
|
|
|
- WarningsHandler warningsHandler) {
|
|
|
+ WarningsHandler warningsHandler, RequestConfig requestConfig) {
|
|
|
this.headers = new ArrayList<>(headers);
|
|
|
this.httpAsyncResponseConsumerFactory = httpAsyncResponseConsumerFactory;
|
|
|
this.warningsHandler = warningsHandler;
|
|
|
+ this.requestConfig = requestConfig;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -210,6 +224,17 @@ public final class RequestOptions {
|
|
|
this.warningsHandler = warningsHandler;
|
|
|
return this;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * set RequestConfig, which can set socketTimeout, connectTimeout
|
|
|
+ * and so on by request
|
|
|
+ * @param requestConfig http client RequestConfig
|
|
|
+ * @return Builder
|
|
|
+ */
|
|
|
+ public Builder setRequestConfig(RequestConfig requestConfig) {
|
|
|
+ this.requestConfig = requestConfig;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|