@@ -5,8 +5,13 @@ import type {
55} from "types/open-next" ;
66import type { Wrapper , WrapperHandler } from "types/overrides" ;
77
8- const cfPropNameToHeaderName = {
9- city : "x-open-next-city" ,
8+ const cfPropNameMapping : Record <
9+ string ,
10+ string | [ ( s : string ) => string , string ]
11+ > = {
12+ // The city name is percent-encoded.
13+ // See https://github.com/vercel/vercel/blob/4cb6143/packages/functions/src/headers.ts#L94C19-L94C37
14+ city : [ encodeURIComponent , "x-open-next-city" ] ,
1015 country : "x-open-next-country" ,
1116 regionCode : "x-open-next-region" ,
1217 latitude : "x-open-next-latitude" ,
@@ -46,12 +51,15 @@ const handler: WrapperHandler<
4651 const cfProperties = ( request as any ) . cf as
4752 | Record < string , string | null >
4853 | undefined ;
49- for ( const [ propName , headerName ] of Object . entries (
50- cfPropNameToHeaderName ,
51- ) ) {
54+ for ( const [ propName , mapping ] of Object . entries ( cfPropNameMapping ) ) {
5255 const propValue = cfProperties ?. [ propName ] ;
5356 if ( propValue != null ) {
54- internalEvent . headers [ headerName ] = propValue ;
57+ const [ encode , headerName ] = Array . isArray ( mapping )
58+ ? mapping
59+ : [ null , mapping ] ;
60+ internalEvent . headers [ headerName ] = encode
61+ ? encode ( propValue )
62+ : propValue ;
5563 }
5664 }
5765
0 commit comments