Skip to content

Commit ae4a54a

Browse files
Hard coding token
1 parent c1fc6cb commit ae4a54a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/http/HttpClient.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package org.elasticsearch.xpack.inference.external.http;
99

1010
import org.apache.http.HttpResponse;
11+
import org.apache.http.client.UserTokenHandler;
1112
import org.apache.http.client.config.RequestConfig;
1213
import org.apache.http.client.protocol.HttpClientContext;
1314
import org.apache.http.concurrent.FutureCallback;
@@ -36,6 +37,8 @@
3637
* Provides a wrapper around a {@link CloseableHttpAsyncClient} to move the responses to a separate thread for processing.
3738
*/
3839
public class HttpClient implements Closeable {
40+
public static final String USER_TOKEN = "token";
41+
3942
private static final Logger logger = LogManager.getLogger(HttpClient.class);
4043

4144
enum Status {
@@ -71,6 +74,13 @@ private static CloseableHttpAsyncClient createAsyncClient(
7174
// The apache client will be shared across all connections because it can be expensive to create it
7275
// so we don't want to support cookies to avoid accidental authentication for unauthorized users
7376
clientBuilder.disableCookieManagement();
77+
var userTokenHandler = new UserTokenHandler() {
78+
public Object getUserToken(HttpContext context) {
79+
return USER_TOKEN;
80+
}
81+
82+
};
83+
clientBuilder.setUserTokenHandler(userTokenHandler);
7484
// clientBuilder.disableConnectionState();
7585

7686
/*

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/http/retry/RetryingHttpSender.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import static org.elasticsearch.core.Strings.format;
3434
import static org.elasticsearch.xpack.inference.InferencePlugin.UTILITY_THREAD_POOL_NAME;
35+
import static org.elasticsearch.xpack.inference.external.http.HttpClient.USER_TOKEN;
3536

3637
public class RetryingHttpSender implements RequestSender {
3738

@@ -214,7 +215,7 @@ public void send(
214215
ActionListener<InferenceServiceResults> listener
215216
) {
216217
var context = HttpClientContext.create();
217-
context.setUserToken("token");
218+
context.setUserToken(USER_TOKEN);
218219
var retrier = new InternalRetrier(logger, request, context, hasRequestTimedOutFunction, responseHandler, listener);
219220
retrier.run();
220221
}

0 commit comments

Comments
 (0)