Skip to content

Commit 0dcf529

Browse files
committed
Allow encoding headers
1 parent e385a58 commit 0dcf529

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

src/handlers/handlerUtils.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,16 @@ function constructRequestHeaders(
108108
}
109109
});
110110
// Remove brotli from accept-encoding because cloudflare has problems with it
111-
if (proxyHeaders['accept-encoding']?.includes('br'))
112-
proxyHeaders['accept-encoding'] = proxyHeaders[
113-
'accept-encoding'
114-
]?.replace('br', '');
111+
// if (proxyHeaders['accept-encoding']?.includes('br'))
112+
// proxyHeaders['accept-encoding'] = proxyHeaders[
113+
// 'accept-encoding'
114+
// ]?.replace('br', '');
115115
}
116116
const baseHeaders: any = {
117117
'content-type': 'application/json',
118+
...(requestHeaders['accept-encoding'] && {
119+
'accept-encoding': requestHeaders['accept-encoding'],
120+
}),
118121
};
119122

120123
let headers: Record<string, string> = {};
@@ -868,19 +871,19 @@ function updateResponseHeaders(
868871
retryAttempt.toString()
869872
);
870873

871-
const contentEncodingHeader = response.headers.get('content-encoding');
872-
if (contentEncodingHeader && contentEncodingHeader.indexOf('br') > -1) {
873-
// Brotli compression causes errors at runtime, removing the header in that case
874-
response.headers.delete('content-encoding');
875-
}
876-
if (getRuntimeKey() == 'node') {
877-
response.headers.delete('content-encoding');
878-
}
874+
// const contentEncodingHeader = response.headers.get('content-encoding');
875+
// if (contentEncodingHeader && contentEncodingHeader.indexOf('br') > -1) {
876+
// // Brotli compression causes errors at runtime, removing the header in that case
877+
// response.headers.delete('content-encoding');
878+
// }
879+
// if (getRuntimeKey() == 'node') {
880+
// response.headers.delete('content-encoding');
881+
// }
879882

880883
// Delete content-length header to avoid conflicts with hono compress middleware
881884
// workerd environment handles this authomatically
882885
response.headers.delete('content-length');
883-
response.headers.delete('transfer-encoding');
886+
// response.headers.delete('transfer-encoding');
884887
if (provider && provider !== POWERED_BY) {
885888
response.headers.append(HEADER_KEYS.PROVIDER, provider);
886889
}

src/handlers/services/responseService.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// responseService.ts
22

3-
import { getRuntimeKey } from 'hono/adapter';
43
import { HEADER_KEYS, POWERED_BY } from '../../globals';
54
import { RESPONSE_HEADER_KEYS } from '../../globals';
65
import { responseHandler } from '../responseHandlers';
@@ -154,12 +153,12 @@ export class ResponseService {
154153
}
155154

156155
// Remove headers directly
157-
const encoding = response.headers.get('content-encoding');
158-
if (encoding?.includes('br') || getRuntimeKey() == 'node') {
159-
response.headers.delete('content-encoding');
160-
}
156+
// const encoding = response.headers.get('content-encoding');
157+
// if (encoding?.includes('br') || getRuntimeKey() == 'node') {
158+
// response.headers.delete('content-encoding');
159+
// }
161160
response.headers.delete('content-length');
162-
response.headers.delete('transfer-encoding');
161+
// response.headers.delete('transfer-encoding');
163162

164163
return response;
165164
}

0 commit comments

Comments
 (0)