sitespeedio / chrome-har

Create HAR files from Chrome Debugging Protocol data
MIT License
149 stars 50 forks source link

Header merging is case-sensitive, causing duplicate headers #125

Open UppaJung opened 3 weeks ago

UppaJung commented 3 weeks ago

Some headers appear twice, once in lowercase and once in mixed-case, because some data structures provide them in lowercase, others in mixed-case, and the header-merging algorithm will include both the mixed-case and lowercase.

I discovered this issue while experimenting with porting/re-writing chrome-har in typescript and trying to replicate chrome-har's current behavior. Please feel free to compare against the typescript implementation to test the fix, or to adopt the code from it, which is also MIT license. (You're free to take the whole thing, but it's a very big change of coding style to adapt to if you don't like typescript.) Sorry that the first you are hearing from me is me filing bugs, but leaving them unreported seemed worse than the alternative.

soulgalore commented 2 weeks ago

Hi @UppaJung thanks, do you have an example trace where the same header comes in different cases? We have code here https://github.com/sitespeedio/chrome-har/blob/main/lib/headers.js#L49-L63 that should have handled it but maybe it's not used everywhere?

UppaJung commented 2 weeks ago

I don't recall which of the existing traces I found this in.

The existing traces produce HARs with headers that are mixed-case, so you could just write a test case that asserts headerName.toLocaleLowercase() is equal to headerName for all existing traces and you should find examples.