Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

HeaderDictionary can't add existing key #489

Description

@tenor

The header dictionary won't allow a header that already exists in the dictionary to be added.

            Response.Headers.Add("Hello", new string[] { "One" });
            Response.Headers.Add("Hello", new string[] { "Two" });

The code above will throw an exception on the second addition.
This was permissible in Web API 2.

        //Web API 2 Example
        // GET api/values
        public IHttpActionResult Get()
        {
            var response = Request.CreateResponse(HttpStatusCode.OK);
            response.Headers.Add("Hello", new string[] { "One" });
            response.Headers.Add("Hello", new string[] { "Two", "Three" });
            return ResponseMessage(response);
        }

In this scenario, Web API 2 adds the header values to the underlying values collection. I think this is the right behavior because that was the developer's intention even though they broke the contract.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions