-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves ClientRequest utilities into their own directory
- Loading branch information
1 parent
6dfc3ad
commit e781074
Showing
8 changed files
with
49 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function bodyBufferToString(buffer: Buffer): string { | ||
const utfEncodedBuffer = buffer.toString('utf8') | ||
const bufferCopy = Buffer.from(utfEncodedBuffer) | ||
const isUtf8 = bufferCopy.equals(buffer) | ||
|
||
return isUtf8 ? utfEncodedBuffer : buffer.toString('hex') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export function concatChunkToBuffer( | ||
chunk: string | Buffer, | ||
buffer: Buffer[] | ||
): Buffer[] { | ||
if (!Buffer.isBuffer(chunk)) { | ||
chunk = Buffer.from(chunk) | ||
} | ||
|
||
return buffer.concat(chunk) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ClientRequest, OutgoingHttpHeaders } from 'http' | ||
|
||
export function inheritRequestHeaders( | ||
req: ClientRequest, | ||
headers: OutgoingHttpHeaders | undefined | ||
): void { | ||
// Cannot write request headers once already written, | ||
// or when no headers are given. | ||
if (req.headersSent || !headers) { | ||
return | ||
} | ||
|
||
Object.entries(headers).forEach(([name, value]) => { | ||
if (value != null) { | ||
req.setHeader(name, value) | ||
} | ||
}) | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
...ientRequest/normalizeHttpRequestParams.ts → ...quest/utils/normalizeHttpRequestParams.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters