feat(header): suggest name of header and combine in one file (#3577)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* feat(header):ssuggest name of header and combine in one file * chore: format and fix jsr path * fix: fix types error of testing
authored by EdamAmex · committed by GitHub · parent cb8244a · Browse files · 7 files·+342 added−83 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+342 added−83 removed
- other:+342 added−83 removed
Provenance
- Commit
e7732a5- Tree
5e3d89c- Author
EdamAmex <121654029+EdamAme-x@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
cb8244a
7 files changed+342 added−83 removed
modified:src/helper/accepts/accepts.ts+1 added-9 removed
12334567891011456766 unmodified linesimport type { Context } from '../../context'import type { AcceptHeader } from '../../utils/headers'
export type AcceptHeader = | 'Accept' | 'Accept-Charset' | 'Accept-Encoding' | 'Accept-Language' | 'Accept-Patch' | 'Accept-Post' | 'Accept-Ranges'
export interface Accept { type: string params: Record<string, string> q: number66 unmodified linesmodified:src/helper/cookie/index.ts+1 added-1 removed
91 unmodified lines92 })93 } else {94 cookie = serialize(name, value, { path: '/', ...opt })95 }96- c.header('set-cookie', cookie, { append: true })96+ c.header('Set-Cookie', cookie, { append: true })97 }98 99 export const setSignedCookie = async (100 c: Context,30 unmodified linesadded:src/utils/headers.ts+333 added
1+/**2+ * @module3+ * HTTP Headers utility.4+ */5+6+// note: https://www.iana.org/assignments/http-fields/http-fields.xhtml7+8+export type RequestHeader =9+ | 'A-IM'10+ | 'Accept'11+ | 'Accept-Additions'12+ | 'Accept-CH'13+ | 'Accept-Charset'14+ | 'Accept-Datetime'15+ | 'Accept-Encoding'16+ | 'Accept-Features'17+ | 'Accept-Language'18+ | 'Accept-Patch'19+ | 'Accept-Post'20+ | 'Accept-Ranges'21+ | 'Accept-Signature'22+ | 'Access-Control'23+ | 'Access-Control-Allow-Credentials'24+ | 'Access-Control-Allow-Headers'25+ | 'Access-Control-Allow-Methods'26+ | 'Access-Control-Allow-Origin'27+ | 'Access-Control-Expose-Headers'28+ | 'Access-Control-Max-Age'29+ | 'Access-Control-Request-Headers'30+ | 'Access-Control-Request-Method'31+ | 'Age'32+ | 'Allow'33+ | 'ALPN'34+ | 'Alt-Svc'35+ | 'Alt-Used'36+ | 'Alternates'37+ | 'AMP-Cache-Transform'38+ | 'Apply-To-Redirect-Ref'39+ | 'Authentication-Control'40+ | 'Authentication-Info'41+ | 'Authorization'42+ | 'Available-Dictionary'43+ | 'C-Ext'44+ | 'C-Man'45+ | 'C-Opt'46+ | 'C-PEP'47+ | 'C-PEP-Info'48+ | 'Cache-Control'49+ | 'Cache-Status'50+ | 'Cal-Managed-ID'51+ | 'CalDAV-Timezones'52+ | 'Capsule-Protocol'53+ | 'CDN-Cache-Control'54+ | 'CDN-Loop'55+ | 'Cert-Not-After'56+ | 'Cert-Not-Before'57+ | 'Clear-Site-Data'58+ | 'Client-Cert'59+ | 'Client-Cert-Chain'60+ | 'Close'61+ | 'CMCD-Object'62+ | 'CMCD-Request'63+ | 'CMCD-Session'64+ | 'CMCD-Status'65+ | 'CMSD-Dynamic'66+ | 'CMSD-Static'67+ | 'Concealed-Auth-Export'68+ | 'Configuration-Context'69+ | 'Connection'70+ | 'Content-Base'71+ | 'Content-Digest'72+ | 'Content-Disposition'73+ | 'Content-Encoding'74+ | 'Content-ID'75+ | 'Content-Language'76+ | 'Content-Length'77+ | 'Content-Location'78+ | 'Content-MD5'79+ | 'Content-Range'80+ | 'Content-Script-Type'81+ | 'Content-Security-Policy'82+ | 'Content-Security-Policy-Report-Only'83+ | 'Content-Style-Type'84+ | 'Content-Type'85+ | 'Content-Version'86+ | 'Cookie'87+ | 'Cookie2'88+ | 'Cross-Origin-Embedder-Policy'89+ | 'Cross-Origin-Embedder-Policy-Report-Only'90+ | 'Cross-Origin-Opener-Policy'91+ | 'Cross-Origin-Opener-Policy-Report-Only'92+ | 'Cross-Origin-Resource-Policy'93+ | 'CTA-Common-Access-Token'94+ | 'DASL'95+ | 'Date'96+ | 'DAV'97+ | 'Default-Style'98+ | 'Delta-Base'99+ | 'Deprecation'100+ | 'Depth'101+ | 'Derived-From'102+ | 'Destination'103+ | 'Differential-ID'104+ | 'Dictionary-ID'105+ | 'Digest'106+ | 'DPoP'107+ | 'DPoP-Nonce'108+ | 'Early-Data'109+ | 'EDIINT-Features'110+ | 'ETag'111+ | 'Expect'112+ | 'Expect-CT'113+ | 'Expires'114+ | 'Ext'115+ | 'Forwarded'116+ | 'From'117+ | 'GetProfile'118+ | 'Hobareg'119+ | 'Host'120+ | 'HTTP2-Settings'121+ | 'If'122+ | 'If-Match'123+ | 'If-Modified-Since'124+ | 'If-None-Match'125+ | 'If-Range'126+ | 'If-Schedule-Tag-Match'127+ | 'If-Unmodified-Since'128+ | 'IM'129+ | 'Include-Referred-Token-Binding-ID'130+ | 'Isolation'131+ | 'Keep-Alive'132+ | 'Label'133+ | 'Last-Event-ID'134+ | 'Last-Modified'135+ | 'Link'136+ | 'Link-Template'137+ | 'Location'138+ | 'Lock-Token'139+ | 'Man'140+ | 'Max-Forwards'141+ | 'Memento-Datetime'142+ | 'Meter'143+ | 'Method-Check'144+ | 'Method-Check-Expires'145+ | 'MIME-Version'146+ | 'Negotiate'147+ | 'NEL'148+ | 'OData-EntityId'149+ | 'OData-Isolation'150+ | 'OData-MaxVersion'151+ | 'OData-Version'152+ | 'Opt'153+ | 'Optional-WWW-Authenticate'154+ | 'Ordering-Type'155+ | 'Origin'156+ | 'Origin-Agent-Cluster'157+ | 'OSCORE'158+ | 'OSLC-Core-Version'159+ | 'Overwrite'160+ | 'P3P'161+ | 'PEP'162+ | 'PEP-Info'163+ | 'Permissions-Policy'164+ | 'PICS-Label'165+ | 'Ping-From'166+ | 'Ping-To'167+ | 'Position'168+ | 'Pragma'169+ | 'Prefer'170+ | 'Preference-Applied'171+ | 'Priority'172+ | 'ProfileObject'173+ | 'Protocol'174+ | 'Protocol-Info'175+ | 'Protocol-Query'176+ | 'Protocol-Request'177+ | 'Proxy-Authenticate'178+ | 'Proxy-Authentication-Info'179+ | 'Proxy-Authorization'180+ | 'Proxy-Features'181+ | 'Proxy-Instruction'182+ | 'Proxy-Status'183+ | 'Public'184+ | 'Public-Key-Pins'185+ | 'Public-Key-Pins-Report-Only'186+ | 'Range'187+ | 'Redirect-Ref'188+ | 'Referer'189+ | 'Referer-Root'190+ | 'Referrer-Policy'191+ | 'Refresh'192+ | 'Repeatability-Client-ID'193+ | 'Repeatability-First-Sent'194+ | 'Repeatability-Request-ID'195+ | 'Repeatability-Result'196+ | 'Replay-Nonce'197+ | 'Reporting-Endpoints'198+ | 'Repr-Digest'199+ | 'Retry-After'200+ | 'Safe'201+ | 'Schedule-Reply'202+ | 'Schedule-Tag'203+ | 'Sec-GPC'204+ | 'Sec-Purpose'205+ | 'Sec-Token-Binding'206+ | 'Sec-WebSocket-Accept'207+ | 'Sec-WebSocket-Extensions'208+ | 'Sec-WebSocket-Key'209+ | 'Sec-WebSocket-Protocol'210+ | 'Sec-WebSocket-Version'211+ | 'Security-Scheme'212+ | 'Server'213+ | 'Server-Timing'214+ | 'Set-Cookie'215+ | 'Set-Cookie2'216+ | 'SetProfile'217+ | 'Signature'218+ | 'Signature-Input'219+ | 'SLUG'220+ | 'SoapAction'221+ | 'Status-URI'222+ | 'Strict-Transport-Security'223+ | 'Sunset'224+ | 'Surrogate-Capability'225+ | 'Surrogate-Control'226+ | 'TCN'227+ | 'TE'228+ | 'Timeout'229+ | 'Timing-Allow-Origin'230+ | 'Topic'231+ | 'Traceparent'232+ | 'Tracestate'233+ | 'Trailer'234+ | 'Transfer-Encoding'235+ | 'TTL'236+ | 'Upgrade'237+ | 'Urgency'238+ | 'URI'239+ | 'Use-As-Dictionary'240+ | 'User-Agent'241+ | 'Variant-Vary'242+ | 'Vary'243+ | 'Via'244+ | 'Want-Content-Digest'245+ | 'Want-Digest'246+ | 'Want-Repr-Digest'247+ | 'Warning'248+ | 'WWW-Authenticate'249+ | 'X-Content-Type-Options'250+ | 'X-Frame-Options'251+252+export type ResponseHeader =253+ | 'Access-Control-Allow-Credentials'254+ | 'Access-Control-Allow-Headers'255+ | 'Access-Control-Allow-Methods'256+ | 'Access-Control-Allow-Origin'257+ | 'Access-Control-Expose-Headers'258+ | 'Access-Control-Max-Age'259+ | 'Age'260+ | 'Allow'261+ | 'Cache-Control'262+ | 'Clear-Site-Data'263+ | 'Content-Disposition'264+ | 'Content-Encoding'265+ | 'Content-Language'266+ | 'Content-Length'267+ | 'Content-Location'268+ | 'Content-Range'269+ | 'Content-Security-Policy'270+ | 'Content-Security-Policy-Report-Only'271+ | 'Content-Type'272+ | 'Cookie'273+ | 'Cross-Origin-Embedder-Policy'274+ | 'Cross-Origin-Opener-Policy'275+ | 'Cross-Origin-Resource-Policy'276+ | 'Date'277+ | 'ETag'278+ | 'Expires'279+ | 'Last-Modified'280+ | 'Location'281+ | 'Permissions-Policy'282+ | 'Pragma'283+ | 'Retry-After'284+ | 'Save-Data'285+ | 'Sec-CH-Prefers-Color-Scheme'286+ | 'Sec-CH-Prefers-Reduced-Motion'287+ | 'Sec-CH-UA'288+ | 'Sec-CH-UA-Arch'289+ | 'Sec-CH-UA-Bitness'290+ | 'Sec-CH-UA-Form-Factor'291+ | 'Sec-CH-UA-Full-Version'292+ | 'Sec-CH-UA-Full-Version-List'293+ | 'Sec-CH-UA-Mobile'294+ | 'Sec-CH-UA-Model'295+ | 'Sec-CH-UA-Platform'296+ | 'Sec-CH-UA-Platform-Version'297+ | 'Sec-CH-UA-WoW64'298+ | 'Sec-Fetch-Dest'299+ | 'Sec-Fetch-Mode'300+ | 'Sec-Fetch-Site'301+ | 'Sec-Fetch-User'302+ | 'Sec-GPC'303+ | 'Server'304+ | 'Server-Timing'305+ | 'Service-Worker-Navigation-Preload'306+ | 'Set-Cookie'307+ | 'Strict-Transport-Security'308+ | 'Timing-Allow-Origin'309+ | 'Trailer'310+ | 'Transfer-Encoding'311+ | 'Upgrade'312+ | 'Vary'313+ | 'WWW-Authenticate'314+ | 'Warning'315+ | 'X-Content-Type-Options'316+ | 'X-DNS-Prefetch-Control'317+ | 'X-Frame-Options'318+ | 'X-Permitted-Cross-Domain-Policies'319+ | 'X-Powered-By'320+ | 'X-Robots-Tag'321+ | 'X-XSS-Protection'322+323+export type AcceptHeader =324+ | 'Accept'325+ | 'Accept-Charset'326+ | 'Accept-Encoding'327+ | 'Accept-Language'328+ | 'Accept-Patch'329+ | 'Accept-Post'330+ | 'Accept-Ranges'331+332+// note: `X-${string}` is deprecated333+export type CustomHeader = string & {}modified:src/context.ts+1 added-71 removed
7 unmodified lines8 NotFoundHandler,9 RouterRoute,10 TypedResponse,11 } from './types'12+import type { ResponseHeader } from './utils/headers'13 import { HtmlEscapedCallbackPhase, resolveCallback } from './utils/html'14 import type { RedirectStatusCode, StatusCode } from './utils/http-status'15 import type { BaseMime } from './utils/mime'16 import type {219 unmodified lines236 interface SetHeadersOptions {237 append?: boolean238 }239 239-type ResponseHeader =240- | 'Access-Control-Allow-Credentials'241- | 'Access-Control-Allow-Headers'242- | 'Access-Control-Allow-Methods'243- | 'Access-Control-Allow-Origin'244- | 'Access-Control-Expose-Headers'245- | 'Access-Control-Max-Age'246- | 'Age'247- | 'Allow'248- | 'Cache-Control'249- | 'Clear-Site-Data'250- | 'Content-Disposition'251- | 'Content-Encoding'252- | 'Content-Language'253- | 'Content-Length'254- | 'Content-Location'255- | 'Content-Range'256- | 'Content-Security-Policy'257- | 'Content-Security-Policy-Report-Only'258- | 'Content-Type'259- | 'Cookie'260- | 'Cross-Origin-Embedder-Policy'261- | 'Cross-Origin-Opener-Policy'262- | 'Cross-Origin-Resource-Policy'263- | 'Date'264- | 'ETag'265- | 'Expires'266- | 'Last-Modified'267- | 'Location'268- | 'Permissions-Policy'269- | 'Pragma'270- | 'Retry-After'271- | 'Save-Data'272- | 'Sec-CH-Prefers-Color-Scheme'273- | 'Sec-CH-Prefers-Reduced-Motion'274- | 'Sec-CH-UA'275- | 'Sec-CH-UA-Arch'276- | 'Sec-CH-UA-Bitness'277- | 'Sec-CH-UA-Form-Factor'278- | 'Sec-CH-UA-Full-Version'279- | 'Sec-CH-UA-Full-Version-List'280- | 'Sec-CH-UA-Mobile'281- | 'Sec-CH-UA-Model'282- | 'Sec-CH-UA-Platform'283- | 'Sec-CH-UA-Platform-Version'284- | 'Sec-CH-UA-WoW64'285- | 'Sec-Fetch-Dest'286- | 'Sec-Fetch-Mode'287- | 'Sec-Fetch-Site'288- | 'Sec-Fetch-User'289- | 'Sec-GPC'290- | 'Server'291- | 'Server-Timing'292- | 'Service-Worker-Navigation-Preload'293- | 'Set-Cookie'294- | 'Strict-Transport-Security'295- | 'Timing-Allow-Origin'296- | 'Trailer'297- | 'Transfer-Encoding'298- | 'Upgrade'299- | 'Vary'300- | 'WWW-Authenticate'301- | 'Warning'302- | 'X-Content-Type-Options'303- | 'X-DNS-Prefetch-Control'304- | 'X-Frame-Options'305- | 'X-Permitted-Cross-Domain-Policies'306- | 'X-Powered-By'307- | 'X-Robots-Tag'308- | 'X-XSS-Protection'309-240 interface SetHeaders {241 (name: 'Content-Type', value?: BaseMime, options?: SetHeadersOptions): void242 (name: ResponseHeader, value?: string, options?: SetHeadersOptions): void243 (name: string, value?: string, options?: SetHeadersOptions): void601 unmodified linesmodified:src/request.ts+3 added-1 removed
9 unmodified lines10 ValidationTargets,11 } from './types'12 import { parseBody } from './utils/body'13 import type { BodyData, ParseBodyOptions } from './utils/body'14+import type { CustomHeader, RequestHeader } from './utils/headers'15 import type { Simplify, UnionToIntersection } from './utils/types'16 import { decodeURIComponent_, getQueryParam, getQueryParams } from './utils/url'17 18 type Body = {152 unmodified lines171 * const userAgent = c.req.header('User-Agent')172 * })173 * ```174 */175+ header(name: RequestHeader): string | undefined176 header(name: string): string | undefined175- header(): Record<string, string>177+ header(): Record<RequestHeader | (string & CustomHeader), string>178 header(name?: string) {179 if (name) {180 return this.raw.headers.get(name.toLowerCase()) ?? undefined181 }224 unmodified linesmodified:src/types.ts+2 added-1 removed
5 unmodified lines6 /* eslint-disable @typescript-eslint/no-unused-vars */7 /* eslint-disable @typescript-eslint/no-explicit-any */8 import type { Context } from './context'9 import type { Hono } from './hono'10+import type { CustomHeader, RequestHeader } from './utils/headers'11 import type { StatusCode } from './utils/http-status'12 import type {13 IfAnyThenEmptyObject,14 IsAny,1909 unmodified lines1924 json: any1925 form: Record<string, T | T[]>1926 query: Record<string, string | string[]>1927 param: Record<P, P extends `${infer _}?` ? string | undefined : string>1927- header: Record<string, string>1928+ header: Record<RequestHeader | CustomHeader, string>1929 cookie: Record<string, string>1930 }1931 1932 ////////////////////////////////////////67 unmodified linesmodified:jsr.json+1 added
86 unmodified lines87888990919293949526 unmodified lines86 unmodified lines "./utils/crypto": "./src/utils/crypto.ts", "./utils/encode": "./src/utils/encode.ts", "./utils/filepath": "./src/utils/filepath.ts", "./utils/handler": "./src/utils/handler.ts", "./utils/headers": "./src/utils/headers.ts", "./utils/html": "./src/utils/html.ts", "./utils/http-status": "./src/utils/http-status.ts", "./utils/jwt": "./src/utils/jwt/index.ts", "./utils/jwt/jwa": "./src/utils/jwt/jwa.ts",26 unmodified lines