getRequestEvent
Edit this pageSolid uses Async Local Storage as a way of injecting the request context anywhere on the server. This is also the event that shows up in middleware.
It can be retrieved by getRequestEvent
from "solid-js/web"
.
Request
.request
is the most important property of the RequestEvent
.
This is a Web Request object that represents the current request to the server.
You can access properties off of it such as url
and headers
.
body
, however, does not typically need to be handled directly for things such as server functions or rendering, which already handle mapping.
Response
The getRequestEvent
can also be used to stub out the Response - this extends the options that can pass to the Response constructor
.
This is kept up to date so it can be used to read and write headers and status for the current response.
Change event.response or create a new Response
The getRequestEvent
event is considered global and lasts the life of the request.
Therefore, if you are calling a server function on the server during SSR or an RPC call, setting values on event.response
will reflect on that request.
The returned response will only impact the response when it is an RPC call. This is important because some headers previously set may not be needed to be set for the whole page, but only for a specific request.
Note: This is important to keep in mind when choosing where to set headers and responses.
See this guide on Request Events.