File tree Expand file tree Collapse file tree 3 files changed +30
-29
lines changed Expand file tree Collapse file tree 3 files changed +30
-29
lines changed Original file line number Diff line number Diff line change @@ -24,12 +24,10 @@ import {
2424 waitForCompletedRequest,
2525 buildBodyReader,
2626 shouldKeepAlive,
27- dropDefaultHeaders,
2827 isHttp2,
2928 isAbsoluteUrl,
3029 writeHead,
3130 encodeBodyBuffer,
32- validateHeader,
3331 getEffectivePort
3432} from '../../util/request-utils';
3533import {
@@ -39,13 +37,13 @@ import {
3937 rawHeadersToObject,
4038 rawHeadersToObjectPreservingCase,
4139 flattenPairedRawHeaders,
42- findRawHeader,
4340 pairFlatRawHeaders,
44- findRawHeaderIndex
41+ findRawHeaderIndex,
42+ dropDefaultHeaders,
43+ validateHeader
4544} from '../../util/header-utils';
4645import { streamToBuffer, asBuffer } from '../../util/buffer-utils';
4746import {
48- isLocalhostAddress,
4947 isLocalPortActive,
5048 isSocketLoop,
5149 requireSocketResetSupport,
Original file line number Diff line number Diff line change 1+ import * as http from 'http';
2+
13import {
24 Headers,
5+ OngoingResponse,
36 RawHeaders
47} from "../types";
58
@@ -190,4 +193,28 @@ export function h1HeadersToH2(headers: RawHeaders): RawHeaders {
190193 return headers.filter(([key]) =>
191194 !HTTP2_ILLEGAL_HEADERS.includes(key.toLowerCase())
192195 );
196+ }
197+
198+ // If the user explicitly specifies headers, we tell Node not to handle them,
199+ // so the user-defined headers are the full set.
200+ export function dropDefaultHeaders(response: OngoingResponse) {
201+ // Drop the default headers, so only the headers we explicitly configure are included
202+ [
203+ 'connection',
204+ 'content-length',
205+ 'transfer-encoding',
206+ 'date'
207+ ].forEach((defaultHeader) =>
208+ response.removeHeader(defaultHeader)
209+ );
210+ }
211+
212+ export function validateHeader(name: string, value: string | string[]): boolean {
213+ try {
214+ http.validateHeaderName(name);
215+ http.validateHeaderValue(name, value);
216+ return true;
217+ } catch (e) {
218+ return false;
219+ }
193220}
Original file line number Diff line number Diff line change @@ -107,30 +107,6 @@ export const writeHead = (
107107 }
108108};
109109
110- // If the user explicitly specifies headers, we tell Node not to handle them,
111- // so the user-defined headers are the full set.
112- export function dropDefaultHeaders(response: OngoingResponse) {
113- // Drop the default headers, so only the headers we explicitly configure are included
114- [
115- 'connection',
116- 'content-length',
117- 'transfer-encoding',
118- 'date'
119- ].forEach((defaultHeader) =>
120- response.removeHeader(defaultHeader)
121- );
122- }
123-
124- export function validateHeader(name: string, value: string | string[]): boolean {
125- try {
126- http.validateHeaderName(name);
127- http.validateHeaderValue(name, value);
128- return true;
129- } catch (e) {
130- return false;
131- }
132- }
133-
134110export function isHttp2(
135111 message: | http.IncomingMessage
136112 | http.ServerResponse
You can’t perform that action at this time.
0 commit comments