File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
src/middleware/request-id Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,19 @@ describe('Request ID Middleware', () => {
2929 expect ( await res . text ( ) ) . toBe ( 'hono-is-hot' )
3030 } )
3131
32+ it ( 'Should return custom request id with all valid characters' , async ( ) => {
33+ const validRequestId = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_='
34+ const res = await app . request ( 'http://localhost/requestId' , {
35+ headers : {
36+ 'X-Request-Id' : validRequestId ,
37+ } ,
38+ } )
39+ expect ( res ) . not . toBeNull ( )
40+ expect ( res . status ) . toBe ( 200 )
41+ expect ( res . headers . get ( 'X-Request-Id' ) ) . toBe ( validRequestId )
42+ expect ( await res . text ( ) ) . toBe ( validRequestId )
43+ } )
44+
3245 it ( 'Should return random request id without using request header' , async ( ) => {
3346 const res = await app . request ( 'http://localhost/requestId' , {
3447 headers : {
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ export const requestId = ({
4646 return async function requestId ( c , next ) {
4747 // If `headerName` is empty string, req.header will return the object
4848 let reqId = headerName ? c . req . header ( headerName ) : undefined
49- if ( ! reqId || reqId . length > limitLength || / [ ^ \w \- ] / . test ( reqId ) ) {
49+ if ( ! reqId || reqId . length > limitLength || / [ ^ \w \- = ] / . test ( reqId ) ) {
5050 reqId = generator ( c )
5151 }
5252
You can’t perform that action at this time.
0 commit comments