1
1
import { Context } from 'hono' ;
2
- import { CONTENT_TYPES , POWERED_BY } from '../globals' ;
2
+ import { CONTENT_TYPES } from '../globals' ;
3
3
import {
4
4
constructConfigFromRequestHeaders ,
5
5
tryTargetsRecursively ,
6
6
} from './handlerUtils' ;
7
7
import { RouterError } from '../errors/RouterError' ;
8
- import { env } from 'hono/adapter' ;
9
8
10
9
async function getRequestData ( request : Request , contentType : string ) {
11
10
let finalRequest : any ;
@@ -24,34 +23,6 @@ async function getRequestData(request: Request, contentType: string) {
24
23
return finalRequest ;
25
24
}
26
25
27
- function headersToSend (
28
- headersObj : Record < string , string > ,
29
- customHeadersToIgnore : Array < string >
30
- ) : Record < string , string > {
31
- let final : Record < string , string > = { } ;
32
- const poweredByHeadersPattern = `x-${ POWERED_BY } -` ;
33
- const headersToAvoidForCloudflare = [ 'expect' ] ;
34
- const headersToAvoid = [
35
- ...customHeadersToIgnore ,
36
- ...headersToAvoidForCloudflare ,
37
- ] ;
38
- headersToAvoid . push ( 'content-length' ) ;
39
- Object . keys ( headersObj ) . forEach ( ( key : string ) => {
40
- if (
41
- ! headersToAvoid . includes ( key ) &&
42
- ! key . startsWith ( poweredByHeadersPattern )
43
- ) {
44
- final [ key ] = headersObj [ key ] ;
45
- }
46
- } ) ;
47
-
48
- // Remove brotli from accept-encoding because cloudflare has problems with it
49
- if ( final [ 'accept-encoding' ] ?. includes ( 'br' ) )
50
- final [ 'accept-encoding' ] = final [ 'accept-encoding' ] ?. replace ( 'br' , '' ) ;
51
-
52
- return final ;
53
- }
54
-
55
26
export async function proxyHandler ( c : Context ) : Promise < Response > {
56
27
try {
57
28
let requestHeaders = Object . fromEntries ( c . req . raw . headers ) ;
@@ -65,7 +36,7 @@ export async function proxyHandler(c: Context): Promise<Response> {
65
36
c ,
66
37
camelCaseConfig ,
67
38
request ,
68
- headersToSend ( requestHeaders , env ( c ) . CUSTOM_HEADERS_TO_IGNORE ?? [ ] ) ,
39
+ requestHeaders ,
69
40
'proxy' ,
70
41
c . req . method ,
71
42
'config'
0 commit comments