-
Notifications
You must be signed in to change notification settings - Fork 3.1k
REST: Add property for configuring user agent in http client #13234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,6 +71,8 @@ public class TestHTTPClient { | |
|
|
||
| private static final int PORT = 1080; | ||
| private static final String BEARER_AUTH_TOKEN = "auth_token"; | ||
| private static final String USER_AGENT = "User-Agent"; | ||
| private static final String TEST_USER_AGENT = "Test-User-Agent"; | ||
| private static final String URI = String.format("http://127.0.0.1:%d", PORT); | ||
| private static final ObjectMapper MAPPER = RESTObjectMapper.mapper(); | ||
|
|
||
|
|
@@ -83,7 +85,10 @@ public class TestHTTPClient { | |
| public static void beforeClass() { | ||
| mockServer = startClientAndServer(PORT); | ||
| restClient = | ||
| HTTPClient.builder(ImmutableMap.of()).uri(URI).withAuthSession(AuthSession.EMPTY).build(); | ||
| HTTPClient.builder(ImmutableMap.of(HTTPClient.REST_USER_AGENT, TEST_USER_AGENT)) | ||
| .uri(URI) | ||
| .withAuthSession(AuthSession.EMPTY) | ||
| .build(); | ||
| icebergBuildGitCommitShort = IcebergBuild.gitCommitShortId(); | ||
| icebergBuildFullVersion = IcebergBuild.fullVersion(); | ||
| } | ||
|
|
@@ -461,7 +466,8 @@ private static String addRequestTestCaseAndGetPath(HttpMethod method, Item body, | |
| .withMethod(method.name().toUpperCase(Locale.ROOT)) | ||
| .withHeader("Authorization", "Bearer " + BEARER_AUTH_TOKEN) | ||
| .withHeader(HTTPClient.CLIENT_VERSION_HEADER, icebergBuildFullVersion) | ||
| .withHeader(HTTPClient.CLIENT_GIT_COMMIT_SHORT_HEADER, icebergBuildGitCommitShort); | ||
| .withHeader(HTTPClient.CLIENT_GIT_COMMIT_SHORT_HEADER, icebergBuildGitCommitShort) | ||
| .withHeader(USER_AGENT, TEST_USER_AGENT); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for my understanding, if I have a HTTP client configured to "my-user-agent" and then I later set it to "some-new-agent" on the request level, it will override it at the request level right? Just wanted to double check the order of precedence (not that I expect it to be used in practice that way)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. precisely, request level override always wins over the client level override. |
||
|
|
||
| if (method.usesRequestBody()) { | ||
| mockRequest = mockRequest.withBody(asJson); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
USER_AGENTconstant exists inHttpHeadersclass.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about adding this constant to class
HTTPClient, but if it's only used by test, we might not do that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, I didn't find the constant in the class
org.apache.iceberg.rest.HttpHeaders. Are you referring to another class with the same name?