Skip to content
Myr

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

4 files+16 added−7 removed

modified:deno_dist/request.ts+1 added-1 removed
modified:docs/CONTRIBUTING.md+5 added-1 removed
1# Contribution Guide23Contributions Welcome! We will be grad for your help.3Contributions Welcome! We will be glad for your help.4You can contribute in the following ways.56- Create an Issue - Propose a new feature. Report a bug.7- Pull Request - Fix a bug and typo. Refactor the code.
9 unmodified lines
1718Although, don't worry!19Hono 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.2021## PRs2223Please ensure your PR passes tests with `yarn test:all`. Also please ensure the Deno code is generated with `yarn denoify`.2425## Third-party middleware2627Third-party middleware is not in the core.28It is allowed to depend on other libraries or work only in specific environments, such as only Cloudflare Workers. For examples:
10 unmodified lines
modified:src/hono.test.ts+9 added-4 removed
7 unmodified lines
8import { TrieRouter } from './router/trie-router'9import type { Handler, Next } from './types'10import type { Expect, Equal } from './utils/types'1112// https://stackoverflow.com/a/6566640213function throwExpression(errorMessage: string): never {14 throw new Error(errorMessage)15}1617describe('GET Request', () => {18 const app = new Hono()1920 app.get('/hello', async () => {
495 unmodified lines
516 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 lines
540 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 lines
779 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 })785786 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 })795796 it('query', async () => {
779 unmodified lines
modified:src/request.ts+1 added-1 removed
34 unmodified lines
35 (): 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 | undefined
133 unmodified lines