Skip to content
Myr

feat(context): Add types for `c.header` (#3221)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* feat(context): Add types for `c.header` * use common types (#5) * refactor: apply header types to response * chore: format code ---------

authored by Shotaro Nakamura · committed by GitHub · parent fbed2df · Browse files · 1 file+94 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: EdamAmex <121654029+EdamAme-x@users.noreply.github.com>

Diff stats

1 file+94 added−2 removed

  • other:+94 added−2 removed

1 file+94 added−2 removed

modified:src/context.ts+94 added-2 removed
17 unmodified lines
18 JSONValue,19 SimplifyDeepArray,20} from './utils/types'2122type HeaderRecord = Record<string, string | string[]>22type HeaderRecord = Record<ResponseHeader, string | string[]> | Record<string, string | string[]>2324/**25 * Data type can be a string, ArrayBuffer, or ReadableStream.26 */
200 unmodified lines
227 matchResult?: Result<[H, RouterRoute]>228 path?: string229}230231interface SetHeadersOptions {232 append?: boolean233}234235type ResponseHeader =236 | 'Access-Control-Allow-Credentials'237 | 'Access-Control-Allow-Headers'238 | 'Access-Control-Allow-Methods'239 | 'Access-Control-Allow-Origin'240 | 'Access-Control-Expose-Headers'241 | 'Access-Control-Max-Age'242 | 'Age'243 | 'Allow'244 | 'Cache-Control'245 | 'Clear-Site-Data'246 | 'Content-Disposition'247 | 'Content-Encoding'248 | 'Content-Language'249 | 'Content-Length'250 | 'Content-Location'251 | 'Content-Range'252 | 'Content-Security-Policy'253 | 'Content-Security-Policy-Report-Only'254 | 'Content-Type'255 | 'Cookie'256 | 'Cross-Origin-Embedder-Policy'257 | 'Cross-Origin-Opener-Policy'258 | 'Cross-Origin-Resource-Policy'259 | 'Date'260 | 'ETag'261 | 'Expires'262 | 'Last-Modified'263 | 'Location'264 | 'Permissions-Policy'265 | 'Pragma'266 | 'Retry-After'267 | 'Save-Data'268 | 'Sec-CH-Prefers-Color-Scheme'269 | 'Sec-CH-Prefers-Reduced-Motion'270 | 'Sec-CH-UA'271 | 'Sec-CH-UA-Arch'272 | 'Sec-CH-UA-Bitness'273 | 'Sec-CH-UA-Form-Factor'274 | 'Sec-CH-UA-Full-Version'275 | 'Sec-CH-UA-Full-Version-List'276 | 'Sec-CH-UA-Mobile'277 | 'Sec-CH-UA-Model'278 | 'Sec-CH-UA-Platform'279 | 'Sec-CH-UA-Platform-Version'280 | 'Sec-CH-UA-WoW64'281 | 'Sec-Fetch-Dest'282 | 'Sec-Fetch-Mode'283 | 'Sec-Fetch-Site'284 | 'Sec-Fetch-User'285 | 'Sec-GPC'286 | 'Server'287 | 'Server-Timing'288 | 'Service-Worker-Navigation-Preload'289 | 'Set-Cookie'290 | 'Strict-Transport-Security'291 | 'Timing-Allow-Origin'292 | 'Trailer'293 | 'Transfer-Encoding'294 | 'Upgrade'295 | 'Vary'296 | 'WWW-Authenticate'297 | 'Warning'298 | 'X-Content-Type-Options'299 | 'X-DNS-Prefetch-Control'300 | 'X-Frame-Options'301 | 'X-Permitted-Cross-Domain-Policies'302 | 'X-Powered-By'303 | 'X-Robots-Tag'304 | 'X-XSS-Protection'305306interface SetHeaders {307 (name: ResponseHeader, value?: string, options?: SetHeadersOptions): void308 (name: string, value?: string, options?: SetHeadersOptions): void309}310311type ResponseHeadersInit =312 | [string, string][]313 | Record<string, string>314 | Record<ResponseHeader, string>315 | Headers316317interface ResponseInit {318 headers?: ResponseHeadersInit319 status?: number320 statusText?: string321}322323export const TEXT_PLAIN = 'text/plain; charset=UTF-8'324325/**326 * Sets the headers of a response.
227 unmodified lines
554 * return c.body('Thank you for coming')555 * })556 * ```557 */466 header = (name: string, value: string | undefined, options?: { append?: boolean }): void => {558 header: SetHeaders = (name, value, options): void => {559 // Clear the header560 if (value === undefined) {561 if (this.#headers) {562 this.#headers.delete(name)
338 unmodified lines