Skip to content

Server-side fetch request should have headers #696

Description

@zhendalf

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 

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp2-nice-to-haveSvelteKit cannot be used by a small number of people, quality of life improvements, etc.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions