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

ClientRequest: Supports chunk/encoding in the "end" method #33

Merged
merged 9 commits into from
Jul 14, 2020

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Jul 12, 2020

Changes

  • Adds normalization for ClientRequest.end arguments.
  • Appends a body chunk given to end() method to the existing request body.
  • Propagates given body chunk to end() method to the original call of req.end() (when performing an original request).
  • Merges options.headers and kOutHeaders when resolving requestHeaders present in the intercepted request object.
  • Propagates kOutHeaders on the original request, if such headers were set.

GitHub

Roadmap

  • Ensure the encoding is propagated
  • Add an integration test covering the issue
  • Ensure the request body written through req.write() is also written on the original request:

https://github.com/mswjs/node-request-interceptor/blob/94969084d99969fe8bfb7b684c9b9d298c007d4b/src/http/ClientRequest/ClientRequestOverride.ts#L243-L246

Per spec, it could be enough to just pass the entire request body as the first argument to the req.end() call of the original request.

  • Property type annotate arguments in test for normalizeHttpRequestEndParams function (no any)
  • Capture all headers (both initial options.headers and headers added via this.setHeader())

@kettanaito
Copy link
Member Author

Headers set via ClientRequest.setHeader() are not captured

This is because the this.setHeader() method is not patched. At the moment only the options.headers are captured, so any request headers set after the request has been created are ignored. This is what supertest does when .send({ json: true }) (sending a JSON request body).

@kettanaito kettanaito marked this pull request as ready for review July 14, 2020 08:55
@kettanaito kettanaito merged commit e781074 into master Jul 14, 2020
@kettanaito kettanaito deleted the 32-req-end-args branch July 14, 2020 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ClientRequestOverride.end() does not accept chunk/encoding supertest along with msw for mocks
1 participant