Modifying Request Host
π heyo
I'm trying to create a simple worker that takes a request and replaces the host.
I have a basic worker running but i want it to be able to pass through the body, all the headers and anything else custom in the original request (e.g. the ip).
Note: I didn't use redirect because I want to use the response before returning it to the user.
Any thoughts?
I also tried req.clone_mut() then changing the path but that didn't work.
4 Replies
Hmm found: https://developers.cloudflare.com/workers/examples/modify-request-property/
Maybe I need to use the underlying web_sys::Request and call
web_sys::Request::new_with_str_and_init
. Let me see if I can get that to workModify request property Β· Cloudflare Workers docs
Documentation for Cloudflare Workers, a serverless execution environment that allows you to create entirely new applications or augment existing ones β¦
Hmm I think the problem is I don't know how to call the Request constructor with another request object. Like in the example:
web_sys::Request does not seem to expose this interface, they all take a RequestInit not a Request (unless there's a way to go from a Request -> RequestInit easily?)
Unknown Userβ’16mo ago
Message Not Public
Sign In & Join Server To View
I tried that but unfortunately I needed to modify the URL.
So Kinded needed a
which somehow worked in JavaScript.
Ended up just writing it in javascript instead π https://github.com/jqphu/shadow-traffic
GitHub
GitHub - jqphu/shadow-traffic
Contribute to jqphu/shadow-traffic development by creating an account on GitHub.