Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

[undici] Preflight requests from Safari #82

Open
2 tasks done
Maxime-J opened this issue Mar 13, 2023 · 4 comments · May be fixed by #83
Open
2 tasks done

[undici] Preflight requests from Safari #82

Maxime-J opened this issue Mar 13, 2023 · 4 comments · May be fixed by #83

Comments

@Maxime-J
Copy link

Maxime-J commented Mar 13, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

A thing to be aware of when undici is used.
In a CORS situation, preflight requests from Safari lead to 500 error.

Indeed, Safari sends an OPTIONS request with a content-length: 0 header, which is not well handled by undici in that situation.

It can be fixed by removing that content-length header, if present (Chrome doesn't send it), before calling the proxy function:

if(req.method === 'OPTIONS' && req.headers.hasOwnProperty('content-length')){
  delete req.headers['content-length'];
}
proxy(...
@Uzlopak
Copy link
Contributor

Uzlopak commented Mar 13, 2023

Why not fix it in upstream undici?

@Maxime-J
Copy link
Author

Agree, I didn't expect it to be fixed here.
Just think it's worth mentioning for other users, with a quick fix, as it should be quite common in a proxy situation, and can easily pass under the radar.
I will open an issue in undici linking that one.

@Maxime-J
Copy link
Author

After more digging,
it turns out fast-proxy already handles that content-length header issue for GET and HEAD methods.
Seems logical to fix it here then, I'll submit a PR to add the OPTIONS method.

@Uzlopak
Copy link
Contributor

Uzlopak commented Mar 13, 2023

Looking forward.

@Maxime-J Maxime-J linked a pull request Mar 13, 2023 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants