-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Initialize Headers Dictionary Only Once #4853
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Interesting, can there be duplicate headers in
response.Headers
andresponse.Content.Headers
? Have second ones a high ptiority?Uh oh!
There was an error while loading. Please reload this page.
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.
No. The headers in
Response.Content.Headers
will never exist inresponse.Headers
. #4494 added this to address the lack ofContent-Type
in theWebResponseObject.Headers
. I should also say thatHttpResponseMessage
has it's own conflict resolution for the headers, so we shouldn't have to do anything here.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.
Please clarify - my understanding from #4494 is that
headers
already containsresponse.Content.Headers
, correct?Uh oh!
There was an error while loading. Please reload this page.
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.
That was added in #4494. Previous to that,
WebResponseObject.Headers
did not contain any of the headers inHttpResponseMessage.Content.Headers
. CoreFX has split the response headers so that those related to content are always inHttpResponseMessage.Content.Headers
and the rest of the response headers are inHttpResponseMessage.Headers
.To clarify, I'm not adding or changing any of the logic in this PR for the creation of the Dictionary. Just moving it so that a new dictionary is not created on every Get to
Headers
and to make the logic available outside ofWebResponseObject
. The existing logic is there on purpose and we have existing tests to ensure it.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.
Thanks for clarify.
So
foreach (var entry in response.Content.Headers)
is duplicate code and could we remove it?Sorry for late question - if CoreFX split the headers why we join them again? Only for backward compatibility?
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.
We are joining them for backwards compat. In 5.1 and earlier all headers are in
WebResponseObject.Headers
. In 6.0 the content headers are buried inWebResponseObject.BaseResponse.Content.Headers
unless we promote them to theWebResponseObject.Headers
dictionary. One would reasonably expect theHeaders
property to contain all headers.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.
@markekraus can you please add a comment to the code to clarify that there won't be duplicate headers in
response.Headers
andresponse.Content.Headers
? It would be very helpful to other people who look at the code later.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.
@daxian-dbw should I also include a note about the content headers being added to the headers dictionary for backwards compatibility? or is the note about the distinct headers sufficient?
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 think it would also be helpful to mention the backward compatibility issue. Thanks @markekraus!
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.
Comments added.