Skip to content
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

Handle multiple headers with the same name #21

Closed
3 tasks
kettanaito opened this issue May 12, 2019 · 4 comments · Fixed by #97
Closed
3 tasks

Handle multiple headers with the same name #21

kettanaito opened this issue May 12, 2019 · 4 comments · Fixed by #97
Labels
good first issue Good for newcomers

Comments

@kettanaito
Copy link
Member

kettanaito commented May 12, 2019

https://github.com/kettanaito/msw/blob/fb1e53cf9cb719ea03c7a3f964461cfb84aa54e2/mockServiceWorker.js#L59-L65

Need to ensure multiple headers with the same name can be handled by MockServiceWorker.

This may also mean to adjust the current algorithm for handling headers between client/sw.

Surface

  • Adjust serialization/deserialization of headers in MSW and interceptRequest
  • Adjust public API of context.set() to support setting of multiple headers with the same name
  • Add tests
@kettanaito kettanaito added the good first issue Good for newcomers label Aug 23, 2019
@kettanaito
Copy link
Member Author

Noting down our productive discussion with @redraushan below.

Data structure

I suggest to store the multiple headers in a list of tuples:

// mockServiceWorker.js
// This would need to be constructed dynamically from "req.headers"
const headers = [['name', 'value'], ['name', 'value']]

Current implementation mirrors the req.headers into a new object instance:

https://github.com/open-draft/msw/blob/6b4242845bb6d301252fbd41c0f4818ce4883e5b/mockServiceWorker.js#L62-L65

De-serialization

When accepted from the MSW on the client side in interceptRequest(), the custom reviver function during JSON parsing should be adjusted to handle the list of tuples. Now it passes the object to new Headers() right away.

https://github.com/open-draft/msw/blob/6b4242845bb6d301252fbd41c0f4818ce4883e5b/src/utils/interceptRequest.ts#L15-L17

@kettanaito
Copy link
Member Author

I was going through the open issues and this is one of the most needed things at the moment. I was wondering if you have the time/desire to implement this, @hehehai? Feel free to say no, I'd try to do this some time next week in that case.

@redraushan
Copy link
Contributor

@kettanaito this was the issue that I discussed with you, it’s my bad I literally forgot to implement the changes. If anyone is not taking in 2-3 days, it’s mine 😅

@hehehai
Copy link
Contributor

hehehai commented Mar 20, 2020

@kettanaito I'm sorry, I don't have any ideas at the moment😐

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants