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

Native Node.js fetch fails with attempting DELETE requests #506

Closed
rdmurphy opened this issue Aug 11, 2022 · 4 comments · Fixed by octokit/endpoint.js#354
Closed

Native Node.js fetch fails with attempting DELETE requests #506

rdmurphy opened this issue Aug 11, 2022 · 4 comments · Fixed by octokit/endpoint.js#354

Comments

@rdmurphy
Copy link

Hello! This possibly overlaps with @octokit/endpoint — we noticed today after updating to the latest version of @octokit/rest (v19) that any API requests that we make that result in a DELETE request (in our case it's delete a label) now fail when they are ran using Node v18. We think we tracked it down to how @octokit/request now opts into using the native Fetch API.

It appears that node-fetch and undici-fetch (AKA native Node.js fetch) feel differently about DELETE requests that set content-length: 0 (which happens via @octokit/endpoint) without adding a body. node-fetch allows it to happen, undici-fetch throws an error with the UND_ERR_REQ_CONTENT_LENGTH_MISMATCH code.

@gr2m
Copy link
Contributor

gr2m commented Aug 11, 2022

DELETE requests that set content-length: 0

I don't recall the exact reason, but I remember that there was a weird problem with some of GitHub's REST APIs when the content-length: 0 header is not set, I'd have to dig for that one a little, or we could run some tests if it's still necessary at all.

@rdmurphy
Copy link
Author

Forgot to add — I did attempt to hit that DELETE endpoint with native Node.js fetch with a bare fetch() call (with all the proper headers and authentication) and it did work without the passing of content-length: 0 or a body. Unfortunately did not also attempt to hit PATCH and PUT endpoints — I saw that@octokit/endpoint notes the REST API does have unique expectations with those.

@timrogers
Copy link
Contributor

It looks like this is affecting other places too - see octokit/rest.js#190.

Would it be practical to just set the body to an empty string?

timrogers added a commit to octokit/endpoint.js that referenced this issue Sep 5, 2022
…T`/`HEAD` requests with no body

Currently, `DELETE` requests without a body don't work on the
latest Node.js version, v18, because we try to set
`content-length: 0` which is not allowed by the native `fetch`
implementation which is included. It throws an error with
the `UND_ERR_REQ_CONTENT_LENGTH_MISMATCH` code.

This stops manually setting that `content-length: 0` header
for `DELETE` requests - and also `PUT`, `POST` and `PATCH`
requests, given that it doesn't actually seem to be required.

I've tested this against the GitHub API with Node.js v18
and v17, and both work as expected, with the GitHub API also
accepting the request.

Fixes octokit/request.js#506.
timrogers added a commit to octokit/endpoint.js that referenced this issue Sep 6, 2022
…` requests with no body

Currently, `DELETE` requests without a body don't work on the
latest Node.js version, v18, because we try to set
`content-length: 0` which is not allowed by the native `fetch`
implementation which is included in Node. It throws an error
with the `UND_ERR_REQ_CONTENT_LENGTH_MISMATCH` code.

This stops manually setting that `content-length: 0` header
for `DELETE` requests.

I've tested this against the GitHub API with Node.js v18
and v17, and both work as expected, with the GitHub API also
accepting the request.

As part of this PR, I've also added some new tests covering
what happens with different HTTP methods.

Fixes octokit/request.js#506.
timrogers added a commit to octokit/endpoint.js that referenced this issue Sep 6, 2022
…` requests with no body (#354)

Currently, `DELETE` requests without a body don't work on the
latest Node.js version, v18, because we try to set
`content-length: 0` which is not allowed by the native `fetch`
implementation which is included in Node. It throws an error
with the `UND_ERR_REQ_CONTENT_LENGTH_MISMATCH` code.

This stops manually setting that `content-length: 0` header
for `DELETE` requests.

I've tested this against the GitHub API with Node.js v18
and v17, and both work as expected, with the GitHub API also
accepting the request.

As part of this PR, I've also added some new tests covering
what happens with different HTTP methods.

Fixes octokit/request.js#506.
@gr2m
Copy link
Contributor

gr2m commented Sep 6, 2022

@rdmurphy can you confirm that the problems is resolved for you via @octokit/endpoint@7.0.2? Make sure to do a fresh install to get the latest version of @octokit/endpoint (rm -rf package-lock.json node_modules && npm install)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants