Svelte

Server-side fetch request should have headers

#696

Development PRs

Issue

Solved
Z
zhendalf
Mar 26, 2021, 2:26 AM

Fetch call made from the server should have the same headers, as the one made from the client.

<!-- index.svelte -->
<script context="module">

export async function load({ fetch }) {
  const { headers }  = await fetch('/content.json').then(res => res.json())
  return { 
    props: { headers }
  }
};

</script>
// content.json.ts
export const get = (request) => ({
  body: {
    headers: request.headers // <- headers: {} if requested during SSR, but populated otherwise
  }
});

In the above case the request.headers are empty ({}) if requested during SSR, but populated when requested from the client on navigation or if requested directly.

The expected behavior is that in both cases the headers are populated and requests look the same.

envinfo:

  npmPackages:
    @sveltejs/adapter-node: next => 1.0.0-next.10 
    @sveltejs/kit: next => 1.0.0-next.60 
    svelte: ^3.29.0 => 3.35.0 
👍 13

Info

Closed at Feb 1, 2022, 5:09 PM
Assignees None
Labels bug, p2-nice-to-have
Milestone None

Pro tip: You can prefix GitHub URLs of issues, PRs or discussions with svcl.dev/ to view them on this page! Also try it on a GitHub release ;)