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

Prevent duplicated/conflicting HTTP headers for HurlStack #193

Merged
merged 3 commits into from
May 24, 2018

Conversation

jpd236
Copy link
Collaborator

@jpd236 jpd236 commented May 23, 2018

  • Don't send two Content-Type headers - let the getHeaders() one win out.
  • Have getHeaders() values take precedence over cache headers

See #139 for more discussion and investigation.

houtianze and others added 2 commits May 23, 2018 14:08
Values returned by getHeaders() should take precedence over both the
additionalHeaders passed into performRequest (which come from the
cache layer) and any Content-Type header set from getPostBodyType().
This allows the client app to hold ultimate control of all headers via
getHeaders().
@jpd236 jpd236 requested a review from jjoslin May 23, 2018 21:49
@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@jpd236
Copy link
Collaborator Author

jpd236 commented May 23, 2018

@houtianze FYI - I am assuming your consent from the initial PR in #139 where your commit was sourced from.

map.putAll(additionalHeaders);
map.putAll(request.getHeaders());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably worth adding a comment about the ordering of these putAll() calls.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a unit test that verifies this behavior?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added comments and a conformance test of sorts. (It would be neat if there were some way to export the conformance test so it'd be easy to run against other HttpStack implementations, but I'm not sure how to do that short of creating a whole new volley-test library).

@jpd236
Copy link
Collaborator Author

jpd236 commented May 24, 2018

PTAL - comments addressed.

@jpd236 jpd236 merged commit 0819be6 into google:master May 24, 2018
@jpd236 jpd236 deleted the header-duplication branch May 24, 2018 19:37
@houtianze
Copy link

@jpd236 Sorry for the late reply, sure, I consent.

jpd236 added a commit to jpd236/volley that referenced this pull request Jun 14, 2018
In google#193 we moved setting of request headers to after setting the
connection parameters (Content-Type header and request body).
However, setting a request body (or more precisely, calling
HttpUrlConection#getOutputStream) prevents us from setting
additional headers, because the connection is opened already.

Instead, we just skip setting the Content-Type header if one
has already been set via Request#getHeaders. This is a bit more
error-prone, but unlikely to change in the future, and hard to
express in a cleaner way because with the DEPRECATED_GET_OR_POST
method, we need to call getPostBody to determine if the request
will be a GET or POST request, and we should only call this once.

Verified on a real device (as Robolectric did not catch this).

Fixes google#198
jpd236 added a commit that referenced this pull request Jun 14, 2018
In #193 we moved setting of request headers to after setting the
connection parameters (Content-Type header and request body).
However, setting a request body (or more precisely, calling
HttpUrlConection#getOutputStream) prevents us from setting
additional headers, because the connection is opened already.

Instead, we just skip setting the Content-Type header if one
has already been set via Request#getHeaders. This is a bit more
error-prone, but unlikely to change in the future, and hard to
express in a cleaner way because with the DEPRECATED_GET_OR_POST
method, we need to call getPostBody to determine if the request
will be a GET or POST request, and we should only call this once.

Verified on a real device (as Robolectric did not catch this).

Fixes #198
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.

4 participants