HttpHeader
HttpHeader
is a component that allows you set a header on the HTTP response sent by the server.
tsx
<HttpHeader ="x-robots-tog" name ="noindex" /> value
tsx
<HttpHeader ="x-robots-tog" name ="noindex" /> value
Usage
Setting a header for catch-all routes
routes/*404.tsx
tsx
import {, HttpHeader } from "solid-start/server"; HttpStatusCode export default function() { NotFound return (<> div <HttpStatusCode ={404} /> code <HttpHeader ="my-header" name ="header-value" /> value </> div );}
routes/*404.tsx
tsx
import {, HttpHeader } from "solid-start/server"; HttpStatusCode export default function() { NotFound return (<> div <HttpStatusCode ={404} /> code <HttpHeader ="my-header" name ="header-value" /> value </> div );}
As you render the page you may want to add additional HTTP headers to the response. The HttpHeader
component will do that for you. You can pass it a name
and value
and that will get added to the Response
headers sent back to the browser.
Keep in mind, when streaming responses(renderStream
), HTTP headers can only be included that are added before the stream first flushed. Be sure to add deferStream
to any resources or createServerData$
calls that needed to be loaded before responding.
Reference
<HttpHeader />
Import from solid-start/server
and use it anywhere in your component tree. It will add the header if that part of the tree is rendered on the server.
tsx
import {} from "solid-start/server"; HttpHeader function() { Component return <HttpHeader ="my-header" name ="header-value" /> value }
tsx
import {} from "solid-start/server"; HttpHeader function() { Component return <HttpHeader ="my-header" name ="header-value" /> value }
Props
name
- The name of the header to setvalue
- The value of the header to set