header may return undefined (#884)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* header may return undefined * fixed broken tests * yarn denoify * update CONTRIBUTING
authored by Alex Errant · committed by GitHub · parent 8caa9af · Browse files · 4 files·+16 added−7 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+16 added−7 removed
- tests:+9 added−4 removed
- other:+7 added−3 removed
Provenance
- Commit
d2abad3- Tree
dce2dbd- Author
Alex Errant <109672176+AlexErrant@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
8caa9af
4 files changed+16 added−7 removed
modified:deno_dist/request.ts+1 added-1 removed
34 unmodified lines35363738393940414243133 unmodified linesExpand all34 unmodified lines (): Record<string, string[]> } headerData?: Record<string, string> header: { (name: string): string (name: string): string | undefined (): Record<string, string> } cookie: { (name: string): string | undefined133 unmodified linesExpand allmodified:docs/CONTRIBUTING.md+5 added-1 removed
1 # Contribution Guide2 3-Contributions Welcome! We will be grad for your help.3+Contributions Welcome! We will be glad for your help.4 You can contribute in the following ways.5 6 - Create an Issue - Propose a new feature. Report a bug.7 - Pull Request - Fix a bug and typo. Refactor the code.9 unmodified lines17 18 Although, don't worry!19 Hono is tested well, polished by the contributors, and used by many developers. And I'll try my best to make Hono cool, beautiful, and ultrafast.20 21+## PRs22+23+Please ensure your PR passes tests with `yarn test:all`. Also please ensure the Deno code is generated with `yarn denoify`.24+25 ## Third-party middleware26 27 Third-party middleware is not in the core.28 It is allowed to depend on other libraries or work only in specific environments, such as only Cloudflare Workers. For examples:10 unmodified linesmodified:src/hono.test.ts+9 added-4 removed
7 unmodified lines8 import { TrieRouter } from './router/trie-router'9 import type { Handler, Next } from './types'10 import type { Expect, Equal } from './utils/types'11 12+// https://stackoverflow.com/a/6566640213+function throwExpression(errorMessage: string): never {14+ throw new Error(errorMessage)15+}16+17 describe('GET Request', () => {18 const app = new Hono()19 20 app.get('/hello', async () => {495 unmodified lines516 await next()517 })518 .use(async (c, next) => {519 await next()515- c.header('x-after', c.req.header('x-before'))520+ c.header('x-after', c.req.header('x-before') ?? throwExpression('missing `x-before` header'))521 })522 .get('/chained/abc', (c) => {523 return c.text('GET chained')524 })15 unmodified lines540 await next()541 },542 async (c, next) => {543 await next()539- c.header('x-after', c.req.header('x-before'))544+ c.header('x-after', c.req.header('x-before') ?? throwExpression('missing `x-before` header'))545 }546 )547 .get('/multiple/abc', (c) => {548 return c.text('GET multiple')230 unmodified lines779 const header = c.req.header('User-Agent')780 await next()781 c.header('X-Query-2', query)782 c.header('X-Param-2', param)778- c.header('X-Header-2', header)783+ c.header('X-Header-2', header ?? throwExpression('missing `X-Header-2` header'))784 })785 786 app.get('/:foo', (c) => {787 const query = c.req.query('foo')788 const param = c.req.param('foo')789 const header = c.req.header('User-Agent')790 c.header('X-Query', query)791 c.header('X-Param', param)787- c.header('X-Header', header)792+ c.header('X-Header', header ?? throwExpression('missing `X-Header` header'))793 return c.body('Hono')794 })795 796 it('query', async () => {779 unmodified linesmodified:src/request.ts+1 added-1 removed
34 unmodified lines35 (): Record<string, string[]>36 }37 headerData?: Record<string, string>38 header: {39- (name: string): string39+ (name: string): string | undefined40 (): Record<string, string>41 }42 cookie: {43 (name: string): string | undefined133 unmodified lines