solid-start icon indicating copy to clipboard operation
solid-start copied to clipboard

Expose responseHeaders to createServerData$

Open oscartbeaumont opened this issue 3 years ago • 0 comments

This PR exposes a way to set HTTP headers on the response within the createServerData$ function.

This makes it possible to do:

export function routeData() {
  return createServerData$((_, { responseHeaders }) => {
    responseHeaders.append("x-demo", "123");

    return "mydata";
  });
}

This will set the headers both on the HTML document (with SSR) and on the fetch request when a client-side navigation is done.

Existing solutions?

Currently, you can use useRequest().responseHeaders to set headers on the response for the HTML document, however, if the user does a client-side navigate a fetch request is done to get that data and when that is done useRequest() is an empty object which can't be used to set the response headers.

Why is this useful?

It is very useful to be able to set cookies on the response. For example, I am trying to do the double submit cookie technique for CSRF protection while integrating SolidStart with NextAuth.js.

oscartbeaumont avatar Nov 27 '22 06:11 oscartbeaumont