question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ResponseData.Headers can't deal with multiple headers with same name

See original GitHub issue

Description

The Headers field of the ResponseData is a map of header name to header value. This assumes that every header type can be set only once, but this is assumption is not correct. E.g. the Set-Cookie may be listen multiple times.

In System.Net.Http this is solved by using a Map which maps the header name to a list of values.

Complete minimal example reproducing the issue

When intercepting the http request, it is not possible to set multiple cookies:

E.g.

        private async Task InterceptAsync(RequestEventArgs args)
        {
            var responseData = new ResponseData
            {
                Body = "{\"success\": true}",
                ContentType = "application/json; charset=utf-8",
                Headers = new Dictionary<string, object>(),
                Status = HttpStatusCode.OK
            };
            
            responseData.Headers.Add("Set-Cookie", "session=xyz; path=/; samesite=none");
            responseData.Headers.Add("Set-Cookie", "addition=abc; path=/; samesite=none");

            await args.Request.RespondAsync(responseData);
        }

Expected behavior:

It should be possible to set headers multiple times with same name.

Actual behavior:

Only one value per header name can be added.

Versions

  • PuppeteerSharp: 2.0.4
  • .NET: .NET Core 3.1.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kblokcommented, Dec 27, 2020

If you can make it work without breaking any test, go for it!

1reaction
L6Echocommented, Aug 19, 2020

The headers property is an Array of HeaderEntries. So it should be possible to set multiple headers with the same name. Except the protocol checks for uniqueness of header names. But I wouldn’t expect this. Because it is a legit case.

Yes, currently i did a workaround with SetCookieAsync. But this bypasses the cookie handling of chrome and this may distort the test result. Additional the cookie header must be parsed manually which may also behave different than the chrome cookie handling itself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set more than one HTTP header with the same name?
A recipient MAY combine multiple header fields with the same field name into one field-name: field-value pair, without changing the semantics of ...
Read more >
multiple headers of the "same name" allowed in http #3591
It seems like the solution here is to either allow multiple "same name" headers, or, fail loudly when the user tries to send...
Read more >
Setting multiple response headers with same name ...
Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header...
Read more >
Back to Basics: Custom HTTP Response Header Manipulation ...
Custom HTTP Headers can be important in applications that need to explicitly manipulate headers either for system and security purposes, ...
Read more >
Multiple header values with the same name
If the request is sent with multiple headers that are sharing the same name, then the HTTPie will send them individually. It is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found