Astro.request
Astro.request is the standard Request object for the current page request.
Syntax
const ua = Astro.request.headers.get('user-agent') Returns
Request — A standard Fetch API Request representing the incoming request.
Examples
---
const ua = Astro.request.headers.get('user-agent') ?? '';
const isBot = /bot|crawler/i.test(ua);
---
<p>{isBot ? 'Hello crawler' : 'Hello human'}</p>
Output
Renders a different greeting depending on the request User-Agent header.
Notes
Fully populated only in on-demand (SSR) rendered routes; in static builds headers and method are not meaningful. Use it to read headers, method, and body in server routes.