Skip to content

Commit 595072c

Browse files
committed
Update client to use new Node header features
1 parent cc55e77 commit 595072c

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

src/client/client-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export interface RequestOptions {
5353
* Each certificate should be an object with a `cert` key containing the PEM
5454
* certificate as a string.
5555
*/
56-
additionalTrustedCAs: Array<{ cert: string }>;
56+
additionalTrustedCAs?: Array<{ cert: string }>;
5757

5858
/**
5959
* Deprecated alias for `additionalTrustedCAs`

src/client/http-client.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ export class HttpClient {
8484
method: requestDefn.method,
8585
signal: options.abortSignal,
8686

87+
setDefaultHeaders: false,
88+
headers: flattenPairedRawHeaders(requestDefn.headers),
89+
8790
// Low-level connection configuration:
8891
agent,
8992
lookup: this.getDns(options.lookupOptions?.servers),
@@ -101,7 +104,7 @@ export class HttpClient {
101104
? tls.rootCertificates.concat(additionalCAs.map(({ cert }) => cert))
102105
: undefined
103106
})
104-
});
107+
} as any); // Would be nice to avoid this but raw header options aren't in the types yet
105108

106109
if (options.keyLogFile) {
107110
request.on('socket', (socket) => {
@@ -114,19 +117,6 @@ export class HttpClient {
114117
request.abort();
115118
});
116119

117-
// Node supports sending raw headers via [key, value, key, value] array, but if we do
118-
// so with 'headers' above then we can't removeHeader first (to disable the defaults).
119-
// Instead we remove headers and then manually trigger the 'raw' write behaviour.
120-
121-
request.removeHeader('connection');
122-
request.removeHeader('transfer-encoding');
123-
request.removeHeader('content-length');
124-
125-
(request as any)._storeHeader(
126-
request.method + ' ' + request.path + ' HTTP/1.1\r\n',
127-
flattenPairedRawHeaders(requestDefn.headers)
128-
);
129-
130120
if (requestDefn.rawBody?.byteLength) {
131121
request.end(requestDefn.rawBody);
132122
} else {

0 commit comments

Comments
 (0)