unjs / unenv

🕊️ Convert javaScript code to be runtime agnostic

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Please reflect the request changes in the CallContext with the createCall function

yumaishida opened this issue · comments

Describe the feature

I think the createCall function generates an IncomingMessage (request) from the CallContext and executes the handle function passed as the argument of the createCall function.

If the URL or header of the IncomingMessage (request) is changed in this handle function, would it be possible to add a process to reflect those changes in the CallContext after the handle function is executed?

Background

I am implementing an edge proxy library based on unjs/h3 that performs authentication and authorization for static websites running in various edge environments that run in front of CDNs, such as AWS Lambda@Edge (Viewer Request trigger), with reference to unjs/nitro. In an edge environment running in front of a CDN, I believe there is a use case for making changes to the original request and delegating the request to a subsequent process (the CDN's content return process).

We would like to implement a process to change the URL of the original request or to change the header in the edge proxy process, but if we use the createCall function of unjs/unenv as is, there is currently no way to know if the request has been changed within the handle function passed as an argument. It would be great if the createCall function could reflect changes in the CallContext (we are currently implementing such a process on our own).

Additional information

  • Would you be willing to help implement this feature?

Hi dear @yumaishida I think it makes sense to be able to have the same functionality but probably directly in h3.

Please check latest PRs particularly on 1.8 RC. New global hooks allow you to intercept latest status of event (modified path, headers, etc (unjs/h3#482) and also we are introducing direct plain and web adapters (unjs/h3#483).

Please let me know what you think, feel free to open issues in unjs/h3 if you have any ideas or questions or ping me to reopen if still belive we could land something in unenv too.