Skip to content
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

ApacheHttpClientRedirectInstrumentation copy headers from original request to redirect if original redirect headers were empty #1539

Merged
merged 2 commits into from
Jun 5, 2020

Conversation

lpriima
Copy link
Contributor

@lpriima lpriima commented Jun 4, 2020

ApacheHttpClientRedirectInstrumentation:
copy headers from original request to redirect request only if original redirect headers were empty without additinal headers

@lpriima lpriima requested a review from a team as a code owner June 4, 2020 14:59
@lpriima lpriima changed the title ApacheHttpClientRedirectInstrumentation copy headers from original re… ApacheHttpClientRedirectInstrumentation copy headers from original request to redirect if original redirect headers were empty Jun 4, 2020
@lpriima lpriima force-pushed the lpriima/copy_headers_if_redirect_headers_were_empty branch 3 times, most recently from 8694b17 to 883cfdd Compare June 4, 2020 15:31
// will be empty. So in case if not-instrumented redirect had no headers,
// we just copy all not set headers from original to redirect (doing same
// thing as apache httpclient does).
if (redirect.getAllHeaders().length == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allocates a new array. Instead you can do

if (!redirect.iterator().hasNext()) {
...
}

which will do a lot less work when there are a lot of headers.

…quest to redirect if original redirect headers were empty
@lpriima lpriima force-pushed the lpriima/copy_headers_if_redirect_headers_were_empty branch from 883cfdd to 17b1c39 Compare June 4, 2020 15:52
Copy link
Contributor

@tylerbenson tylerbenson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we able to see this impact in the tests anywhere?

@randomanderson
Copy link
Contributor

I agree with @tylerbenson . I think this warrants at least 1 test to prevent regressions

@lpriima lpriima force-pushed the lpriima/copy_headers_if_redirect_headers_were_empty branch 2 times, most recently from 4ede207 to fbd8084 Compare June 5, 2020 06:58
Copy link
Contributor

@bantonsson bantonsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Only minor thing is a forgotten println in a test.

@@ -53,6 +55,19 @@ abstract class HttpClientTest extends AgentTestRunner {
handleDistributedRequest()
redirect(server.address.resolve("/circular-redirect").toURL().toString())
}
prefix("secured") {
handleDistributedRequest()
println("secured: " + request.headers.headers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we drop this println?

@lpriima lpriima force-pushed the lpriima/copy_headers_if_redirect_headers_were_empty branch from fbd8084 to 45eb00c Compare June 5, 2020 10:13
@lpriima lpriima merged commit a5afd69 into master Jun 5, 2020
@lpriima lpriima deleted the lpriima/copy_headers_if_redirect_headers_were_empty branch June 5, 2020 10:50
@github-actions github-actions bot added this to the 0.55.0 milestone Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants