-
Notifications
You must be signed in to change notification settings - Fork 120
fix: repeated headers get dropped #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: repeated headers get dropped #327
Conversation
✅ Deploy Preview for chimerical-kitsune-a0bfa0 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Hi, thanks for the PR. This seems like a really good implementation. I have one change required:
The issue is a lot of people use parent and child relationship to override headers / envs. Here the behavior changes to merge. Parent: Child: Final Before: ^ This is useful when most requests in the folder have the same header value but one request needs a different value. Final Now: We can retain the original behavior as is (to prevent breaking existing assumptions) and provide a setting to enable the new behavior. So parent header and child header gets merged together instead of overridden. |
This actually makes a lot of sense
Would the following "business rule" capture this requirement? An example would be:
result: {
"header1": "Value1, Value2", //parent headers merged, child header ignored
"header42": "Value3, Value4", //child headers merged
"header6": "Value9",
"header4": "Value20"
} |
In Restfox, the child always takes precedence, so the above would not be correct. Child gets the final say in what headers it will use, as the request is initiated from the child's side. The requirement would be: Parent: Child: result:
|
Yeah, off course LMAO I did the same mistake again, sorry. Now I get it! |
Looks good! I'll run some manual tests today and we should be good to merge. |
Judging by the output of insomnia and postman, I assume that they are interpreting In my opinion, that's not the most semantic interpretation. If a user defines the same header multiple times, I’d assume they’re intentionally creating a list. In such case I think each individual value should be treated as-is. So if one of the values contains a comma, I think it makes more sense to preserve it as a single value (by quoting it), rather than splitting it further. That being said, I’m honestly not sure how most HTTP header parsers behave in these cases, it may vary, maybe some treat everything as a flat list regardless, if I'm not mistaken express.js does that, everything becomes just a single string. Now, it is an important observation that insomnia and postman use the simpler implementation of just combining the values, ignoring whether commas are part of a value (I assume they also ignore the leading space case). If conformity with those clients is a priority, it makes sense to drop the quoting behavior for consistency. Ultimately, I think you are much more suited to make this decision. I’m not fully aware of the broader goals of the project, especially in terms of how closely we want to mirror the behavior of other clients. |
I think your implementation is the semantically correct one but I think we should go with the same approach as postman and insomnia to avoid breaking expectation of users. Some users might already be using comma separated header values to pass multiple header values in a single header, so our new implementation would break this. |
Thank you. Looks good. Will merge. |
Addresses #321
When the same header name is defined multiple times, all the definitions are compressed into a comma separated list of values (according to RFC/9110-section-5.2)
On the request preview the values are not shown separately, however the original request object does have each header defined individually and parsed correctly
Original Resquest Headers (screenshot)
It also works on folders (or any parent) and the headers will follow the hierarchy order, that is, if a folder defines a header named
X-Custom-Header
asx-value
and a request inside that folder definesX-Custom-Header
asy-value
the end request will have the headerx-value, y-value
(the parent is defined first)Note: when substituting parent header names the end name would be lower-cased but when substituting the leaf header object (the request headers object) the header name would not be lower-cased. For sake of consistency (and correctness) now everything is lower cased
Testing
Manual test on the browser and running electron locally
Preview: