Skip to content
You are reading the v2 docs, currently in beta.V1 docs
oRPC
Esc
↑↓navigate↵open⌘Jpreview
On this page

HEAD Method Plugin

Use HeadMethodHandlerPlugin to answer HEAD requests with the status and headers of the matching GET procedure, without sending its body.

How It Works

A HEAD request asks for the headers a GET request would receive, without the body, so clients, caches, and link checkers can learn whether a resource exists, its type, and its size without downloading it. Like Fastify’s exposeHeadRoutes, the plugin answers a HEAD request that matches no procedure with the matching GET procedure:

  • The response keeps the status and headers of GET, such as Content-Type, Content-Encoding, and ETag, plus Content-Length when the size is known without reading a stream.
  • The body is discarded: streams are cancelled and event iterators end before they start.
  • A procedure routed as HEAD takes precedence over the GET one.
  • The request reaches the procedure as GET, so plugins guarding GET, such as the GET Method CSRF Protection Plugin, guard HEAD too.

Setup

import { OpenAPIHandler } from '@orpc/openapi/fetch'
import { HeadMethodHandlerPlugin } from '@orpc/server/plugins'

const handler = new OpenAPIHandler(router, {
  plugins: [
    new HeadMethodHandlerPlugin(),
  ],
})

Learn More

For implementation details, see the source code.

Last updated on

Was this page helpful?