Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(context): Custom header name for c.header #3289

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,10 @@ type ResponseHeader =
| 'X-Robots-Tag'
| 'X-XSS-Protection'

interface SetHeaders {
interface SetHeaders<E extends Env> {
(name: 'Content-Type', value?: BaseMime, options?: SetHeadersOptions): void
(name: ResponseHeader, value?: string, options?: SetHeadersOptions): void
(name: NonNullable<E['Headers']>, value?: string, options?: SetHeadersOptions): void
(name: string, value?: string, options?: SetHeadersOptions): void
}

Expand Down Expand Up @@ -576,7 +577,7 @@ export class Context<
* })
* ```
*/
header: SetHeaders = (name, value, options): void => {
header: SetHeaders<E> = (name, value, options): void => {
// Clear the header
if (value === undefined) {
if (this.#headers) {
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import type {

export type Bindings = object
export type Variables = object
export type CustomHeaders = string

export type BlankEnv = {}
export type Env = {
Bindings?: Bindings
Variables?: Variables
Headers?: CustomHeaders
}

export type Next = () => Promise<void>
Expand Down