Skip to content

HTTP Headers .toJSON() only returns values (not keys) of the headers #6073

Closed

Description

@choeller

The current implementation of toJSON() of the Headers class only returns a JSON-Object containing all values.:

[
  [
    "no-cache"
  ],
  [
    "application/json; charset=utf-8"
  ],
  [
    "no-cache"
  ],
  [
    "-1"
  ]
]

IMO this should return a JSON Object mapping keys to values.

Activity

  1. added this to the milestone on Dec 28, 2015
  2. robwormald commented on Dec 28, 2015

    @robwormald
    Contributor

    cc @gdi2290 - i know you added this for universal - any input?

  3. PatrickJS commented on Dec 29, 2015

    @PatrickJS
    Contributor

    yeah I can fix that. The idea behind having .toJSON() was being able to recreate it on the client

    var serverHeaders = new Headers();
    serverHeaders.append('Content-Type', 'image/jpeg');
    var serialized = JSON.stringify(serverHeaders, null, 2);
    
    console.log(serialized === `{
      "Content-Type": ["image/jpeg"]
    }`);
    
    var clientHeaders = new Headers(JSON.parse(serialized));
  4. modified the milestones: beta.01, on Jan 25, 2016
  5. PatrickJS commented on Jan 27, 2016

    @PatrickJS
    Contributor

    @choeller @robwormald I have a PR with the correct implementation and tests to ensure that you can also recreate the Header #6714

  6. angular-automatic-lock-bot commented on Sep 7, 2019

    @angular-automatic-lock-bot

    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.

  7. locked and limited conversation to collaborators on Sep 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions