mirror of
https://github.com/honojs/hono.git
synced 2024-12-01 11:51:01 +01:00
Merge branch 'main' into next
This commit is contained in:
commit
0b2ac1678e
@ -68,18 +68,17 @@ export class HonoRequest<P extends string = '/', I extends Input = {}> {
|
||||
return getQueryParams(queryString, key)
|
||||
}
|
||||
|
||||
header(name: string): string
|
||||
header(name: string): string | undefined
|
||||
header(): Record<string, string>
|
||||
header(name?: string) {
|
||||
const headerData: Record<string, string> = {}
|
||||
this.raw.headers.forEach((value, key) => {
|
||||
headerData[key] = value
|
||||
})
|
||||
if (name) {
|
||||
return headerData[name.toLowerCase()]
|
||||
} else {
|
||||
if (!name) {
|
||||
return headerData
|
||||
}
|
||||
return headerData[name.toLowerCase()] || undefined
|
||||
}
|
||||
|
||||
cookie(key: string): string | undefined
|
||||
|
@ -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.
|
||||
|
@ -322,4 +322,4 @@
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
}
|
||||
}
|
||||
}
|
@ -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) => {
|
||||
@ -811,7 +816,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) => {
|
||||
@ -820,7 +825,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')
|
||||
})
|
||||
|
||||
|
@ -68,18 +68,17 @@ export class HonoRequest<P extends string = '/', I extends Input = {}> {
|
||||
return getQueryParams(queryString, key)
|
||||
}
|
||||
|
||||
header(name: string): string
|
||||
header(name: string): string | undefined
|
||||
header(): Record<string, string>
|
||||
header(name?: string) {
|
||||
const headerData: Record<string, string> = {}
|
||||
this.raw.headers.forEach((value, key) => {
|
||||
headerData[key] = value
|
||||
})
|
||||
if (name) {
|
||||
return headerData[name.toLowerCase()]
|
||||
} else {
|
||||
if (!name) {
|
||||
return headerData
|
||||
}
|
||||
return headerData[name.toLowerCase()] || undefined
|
||||
}
|
||||
|
||||
cookie(key: string): string | undefined
|
||||
|
Loading…
Reference in New Issue
Block a user