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

Allow the Request to override the Authorization header set by the Client #121

Closed
wants to merge 1 commit into from

Conversation

arun251
Copy link
Contributor

@arun251 arun251 commented Feb 4, 2018

We have code that sets the Authorization header on the Client object and then overrides the header on the Request object. That previously worked with Resty v0.13 but no longer worked after upgrading to Resty v1.2. The root cause of this issue is in parseRequestHeader where client and request headers are concatenated.

This PR fixes the issue for Authorization, but I suspect there are other singleton headers that could be affected.

@codecov
Copy link

codecov bot commented Feb 4, 2018

Codecov Report

Merging #121 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #121      +/-   ##
==========================================
+ Coverage   96.32%   96.32%   +<.01%     
==========================================
  Files          10       10              
  Lines        1033     1035       +2     
==========================================
+ Hits          995      997       +2     
  Misses         21       21              
  Partials       17       17
Impacted Files Coverage Δ
middleware.go 92.16% <100%> (+0.07%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 00cb083...c501246. Read the comment docs.

@jeevatkm
Copy link
Member

jeevatkm commented Feb 4, 2018

@arun251 Thank you for the PR.

I will verify this behaviour between v0.13 and latest. I good to ensure any other singleton header also is not affected.

@jeevatkm jeevatkm self-assigned this Feb 4, 2018
@jeevatkm jeevatkm added this to the v1.3 Milestone milestone Feb 4, 2018
@jeevatkm
Copy link
Member

jeevatkm commented Feb 4, 2018

@arun251 If there is an issue with singleton headers, that needs to be fixed across not just Authorization. Thanks for your findings. I will analyze and get back to you.

Copy link
Member

@jeevatkm jeevatkm left a comment

Choose a reason for hiding this comment

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

@arun251 I have found the reason and fix for across headers. I have provided fix info via review comments. Can you please update your PR and submit it?

@@ -472,3 +472,20 @@ func TestSetLogPrefix(t *testing.T) {
assertEqual(t, "CUSTOM ", c.logPrefix)
assertEqual(t, "CUSTOM ", c.Log.Prefix())
}

func TestRequestOverridesClientAuthorizationHeader(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Please move this test case to request_test.go file.

@@ -76,6 +76,11 @@ func parseRequestHeader(c *Client, r *Request) error {
hdr[k] = append(hdr[k], r.Header[k]...)
}

// Allow the Request to override the Authorization header set by the Client
Copy link
Member

@jeevatkm jeevatkm Feb 4, 2018

Choose a reason for hiding this comment

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

I have analyzed the v0.13 and latest version. Fix for across headers.

Remove this if condition and update your PR as follows.

Update Line #75 to #77 to following-

for k := range r.Header {
	// remove header from client level by key
	// since overrides happens for that key in the request
	hdr.Del(k)
	
	hdr[k] = append(hdr[k], r.Header[k]...)
}

@jeevatkm
Copy link
Member

jeevatkm commented Feb 6, 2018

@arun251 Awaiting for your PR changes or let me know I will do it.

@arun251
Copy link
Contributor Author

arun251 commented Feb 6, 2018

Please go ahead with the changes. Thanks!

@jeevatkm
Copy link
Member

jeevatkm commented Feb 6, 2018

@arun251 Thank you, I will take your test case and create new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants