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 asContent-Type,Content-Encoding, andETag, plusContent-Lengthwhen 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
HEADtakes precedence over theGETone. - The request reaches the procedure as
GET, so plugins guardingGET, such as the GET Method CSRF Protection Plugin, guardHEADtoo.
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.