npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

hono-query-header-mapper

v1.0.0

Published

Hono middleware for mapping URL query parameters into HTTP headers

Downloads

4

Readme

🔗 hono-query-header-mapper

Hono middleware for mapping URL query parameters into HTTP headers—perfect for situations where headers can’t be set client-side (e.g., presigned URLs, EventSource).

✨ Features

  • Extract a query parameter and set it as any request header
  • Optional transformation of the value (e.g., adding a Bearer prefix)
  • Easy plug-and-play integration with Hono

🛠️ Installation

Install via npm or Yarn:

npm install hono-query-header-mapper
# or
yarn add hono-query-header-mapper

🚀 Usage

Import the middleware and apply it before any header-based handlers (e.g., JWT):

import { Hono } from 'hono'
import { jwt } from 'hono/jwt'
import { queryHeaderMapper } from 'hono-query-header-mapper'

const app = new Hono()

app.use(
  '/protected/*',
  queryHeaderMapper('accessToken', 'Authorization', value => `Bearer ${value}`),
  jwt({ secret: 'YOUR_SECRET_KEY' })
)

app.get('/protected/hello', c => {
  return c.text('Hello, secured world!')
})

app.fire()

📖 API Reference

queryHeaderMapper(queryParam: string, headerName: string, transform?: (value: string) => string)

  • ``: The name of the URL query parameter to read.
  • ``: The HTTP header name to set on the request.
  • `` (optional): A function to transform the raw query value before setting it as the header. Defaults to the identity function.

Returns: A Hono-compatible middleware function: (c: Context, next: Next) => Promise<void>.

🏷️ Common Scenarios

📦 Presigned Download URLs

When using presigned URLs (e.g., AWS S3) you cannot set headers on the client. Include an authentication token as a query parameter and use this middleware to promote it into the Authorization header for downstream handlers.

app.get(
  '/download',
  queryHeaderMapper('token', 'Authorization', t => `Bearer ${t}`),
  downloadHandler
)

🌐 Server-Sent Events (SSE)

The EventSource API does not allow custom headers. Pass session credentials as query parameters and elevate them into headers on the server to secure SSE streams.

app.get(
  '/events',
  queryHeaderMapper('sessionId', 'X-Session-Id'),
  eventStreamHandler
)

🔒 Webhooks and Other Raw Values

Use the middleware without a transformer to forward a raw signature or token:

app.post(
  '/webhook',
  queryHeaderMapper('sig', 'X-Signature'),
  webhookHandler
)

🗂️ Grouped Middleware

You can also apply it within a route group:

app.group('/api', api => {
  api.use(queryHeaderMapper('apiKey', 'X-Api-Key'))
  api.use(jwt({ secret: '...' }))
  api.get('/data', dataHandler)
})

🤝 Contributing

Contributions, issues, and feature requests are welcome! Please open an issue or submit a pull request on GitHub.

📄 License

MIT