From d2abad3b347e6feed9544cd8027f96ff2d4fa00e Mon Sep 17 00:00:00 2001 From: Alex Errant <109672176+AlexErrant@users.noreply.github.com> Date: Sun, 12 Feb 2023 15:30:57 -0600 Subject: [PATCH 1/2] header may return undefined (#884) * header may return undefined * fixed broken tests * yarn denoify * update CONTRIBUTING --- deno_dist/request.ts | 2 +- docs/CONTRIBUTING.md | 6 +++++- src/hono.test.ts | 13 +++++++++---- src/request.ts | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/deno_dist/request.ts b/deno_dist/request.ts index aa17baee..56a8a843 100644 --- a/deno_dist/request.ts +++ b/deno_dist/request.ts @@ -36,7 +36,7 @@ declare global { } headerData?: Record header: { - (name: string): string + (name: string): string | undefined (): Record } cookie: { diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index a83ed714..126ea945 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contribution Guide -Contributions Welcome! We will be grad for your help. +Contributions Welcome! We will be glad for your help. You can contribute in the following ways. - Create an Issue - Propose a new feature. Report a bug. @@ -18,6 +18,10 @@ So, if you propose great ideas, but I do not appropriate them, the idea may not Although, don't worry! 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. +## PRs + +Please ensure your PR passes tests with `yarn test:all`. Also please ensure the Deno code is generated with `yarn denoify`. + ## Third-party middleware Third-party middleware is not in the core. diff --git a/src/hono.test.ts b/src/hono.test.ts index d2ad1b2d..bf5b0071 100644 --- a/src/hono.test.ts +++ b/src/hono.test.ts @@ -9,6 +9,11 @@ import { TrieRouter } from './router/trie-router' import type { Handler, Next } from './types' import type { Expect, Equal } from './utils/types' +// https://stackoverflow.com/a/65666402 +function throwExpression(errorMessage: string): never { + throw new Error(errorMessage) +} + describe('GET Request', () => { const app = new Hono() @@ -512,7 +517,7 @@ describe('Middleware', () => { }) .use(async (c, next) => { await next() - c.header('x-after', c.req.header('x-before')) + c.header('x-after', c.req.header('x-before') ?? throwExpression('missing `x-before` header')) }) .get('/chained/abc', (c) => { return c.text('GET chained') @@ -536,7 +541,7 @@ describe('Middleware', () => { }, async (c, next) => { await next() - c.header('x-after', c.req.header('x-before')) + c.header('x-after', c.req.header('x-before') ?? throwExpression('missing `x-before` header')) } ) .get('/multiple/abc', (c) => { @@ -775,7 +780,7 @@ describe('Request methods with custom middleware', () => { await next() c.header('X-Query-2', query) c.header('X-Param-2', param) - c.header('X-Header-2', header) + c.header('X-Header-2', header ?? throwExpression('missing `X-Header-2` header')) }) app.get('/:foo', (c) => { @@ -784,7 +789,7 @@ describe('Request methods with custom middleware', () => { const header = c.req.header('User-Agent') c.header('X-Query', query) c.header('X-Param', param) - c.header('X-Header', header) + c.header('X-Header', header ?? throwExpression('missing `X-Header` header')) return c.body('Hono') }) diff --git a/src/request.ts b/src/request.ts index e1be51e1..549bb6c1 100644 --- a/src/request.ts +++ b/src/request.ts @@ -36,7 +36,7 @@ declare global { } headerData?: Record header: { - (name: string): string + (name: string): string | undefined (): Record } cookie: { From 93da44042c04c334aa208b93316c86f68ba2e883 Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Mon, 13 Feb 2023 06:35:37 +0900 Subject: [PATCH 2/2] v2.7.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dade5ce2..9b13758f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hono", - "version": "2.7.7", + "version": "2.7.8", "description": "Ultrafast web framework for Cloudflare Workers, Deno, and Bun.", "main": "dist/cjs/index.js", "type": "module",