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

fix(http): preserve header case when copying headers #12697

Merged
merged 1 commit into from
Nov 4, 2016

Conversation

alxhub
Copy link
Member

@alxhub alxhub commented Nov 3, 2016

Please check if the PR fulfills these requirements

What kind of change does this PR introduce? (check one with "x")

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior? (You can also link to an open issue here)

#12106 attempted to preserve the case of HTTP headers added to the Headers object.

It failed, because StaticRequest copies the headers (

this.headers = new Headers(requestOptions.headers);
) and that copy ignores the saved case (
headers._headers.forEach((values: string[], name: string) => {
).

What is the new behavior?

Copying headers preserves their case.

Does this PR introduce a breaking change? (check one with "x")

[ ] Yes
[x] No

If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...

Other information:

@alxhub alxhub added action: review The PR is still awaiting reviews from at least one requested reviewer comp: http labels Nov 3, 2016
@alxhub alxhub force-pushed the http-case-fix branch 2 times, most recently from 876d81a to 3acec37 Compare November 3, 2016 22:06
@vicb
Copy link
Contributor

vicb commented Nov 3, 2016

I think the fix should be

    if (headers instanceof Headers) {
      headers._headers.forEach((values: string[], name: string) => {
        values.forEach(value => this.append(name, value));
      });
      return;
    }

->

    if (headers instanceof Headers) {
      headers.forEach((values: string[], name: string) => {
        values.forEach(value => this.append(name, value));
      });
      return;
    }

(removing ._headers)

@alxhub
Copy link
Member Author

alxhub commented Nov 3, 2016

@vicb updated with your suggested simplification

@vicb vicb added pr_state: LGTM action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Nov 4, 2016
headers.set('fOo', 'baz');
headers.set('foo', 'bat');
headers = new Headers(headers);
expect(JSON.stringify(headers)).toEqual('{"fOo":["bat"]}');
Copy link
Contributor

Choose a reason for hiding this comment

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

expect(JSON.stringify(new Headers(headers))).toEqual('{"fOo":["bat"]}');

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@ModalSeoul
Copy link

Can't wait for this to get pulled.

@vikerman vikerman merged commit 121e508 into angular:master Nov 4, 2016
@ModalSeoul
Copy link

This issue persists.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants