ResponseData.Headers can't deal with multiple headers with same name
See original GitHub issueDescription
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:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you can make it work without breaking any test, go for it!
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.