-
Notifications
You must be signed in to change notification settings - Fork 210
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
Default fetch request headers differ between Cloudflare Workers and Miniflare #139
Comments
Hey! 👋 I think this is going to be difficult to fix. As you can see from the For Not sure what to do here, we could fork |
I'm going to speculate for a minute here. I'm guessing that the desire to use Forking This might be a terrible idea, but what if Miniflare ran its own lightweight proxy endpoint that stripped the offending headers from outbound requests before forwarding to the intended destination, and in this shim You would keep the benefits of having a spec-compatible internal API, while also being compliant with the CF implementation. There would be a small maintenance cost for the proxy, but I imagine it would probably be substantially lower compared to maintaining a fork, particularly considering the very specific transform required. There would be some hoops to jump through when it comes to telling the proxy what to strip, but I imagine something like this would do the trick:
|
Exactly 👍 That's a sneaky idea with the proxy. I'm actually wondering if we could do this with a custom |
Modifying the global dispatcher smells really bad to me. If anything else in Miniflare uses |
Specifically, remove `Accept`, `Accept-Language`, `Sec-Fetch-Mode` and `User-Agent`, unless they are explicitly added by the user. `User-Agent` is particularly important to remove as many APIs (e.g. GitHub), require it to be set, meaning code was working locally but not when deployed. The implementation of this relies on some internal `undici` exports. We were already using some internal symbols for accessing hidden `Request`/`Response` state, so this isn't too bad. The version of `undici` is now pinned to an exact version though, so if internal changes are made, they shouldn't affect end-users. We'll have to explicitly upgrade and run our tests again.
Hey! 👋 I noticed Will be fixed in the next release. 🙂 |
Specifically, remove `Accept`, `Accept-Language`, `Sec-Fetch-Mode` and `User-Agent`, unless they are explicitly added by the user. `User-Agent` is particularly important to remove as many APIs (e.g. GitHub), require it to be set, meaning code was working locally but not when deployed. The implementation of this relies on some internal `undici` exports. We were already using some internal symbols for accessing hidden `Request`/`Response` state, so this isn't too bad. The version of `undici` is now pinned to an exact version though, so if internal changes are made, they shouldn't affect end-users. We'll have to explicitly upgrade and run our tests again.
Hey! 👋 Miniflare |
When making a
fetch
request to an external service from a Worker, certain request headers are populated by default. The Workers runtime and miniflare send different default headers, meaning that when calling some external APIs (e.g. Github's which requires aUser-Agent
header for all requests!) code that works in miniflare will fail when running on the Workers runtime.To validate this, I set up a simple echo service running on https://http-ua-proof-of-concept.dancowell.workers.dev/ which will return a structured JSON object containing request data.
Executing the following worker in each context results in different output:
Request from miniflare
Request from Cloudflare
Based on this output, miniflare sends 4 additional headers by default:
accept, accept-language, sec-fetch-mode, user-agent
I would expect that miniflare's default request headers should match that of the workers runtime.
The text was updated successfully, but these errors were encountered: