socket-function 1.2.18 → 1.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +3 -0
- package/package.json +1 -1
- package/src/https.d.ts +3 -0
- package/src/https.ts +15 -0
package/index.d.ts
CHANGED
package/package.json
CHANGED
package/src/https.d.ts
CHANGED
package/src/https.ts
CHANGED
|
@@ -47,6 +47,8 @@ export function httpsRequest(
|
|
|
47
47
|
config?: {
|
|
48
48
|
headers?: { [key: string]: string | undefined },
|
|
49
49
|
cancel?: Promise<void>;
|
|
50
|
+
// Populated with the response headers once they arrive, so the caller can read them.
|
|
51
|
+
outHeaders?: { [key: string]: string | undefined };
|
|
50
52
|
}
|
|
51
53
|
): Promise<Buffer> {
|
|
52
54
|
if (isNode()) {
|
|
@@ -96,6 +98,12 @@ export function httpsRequest(
|
|
|
96
98
|
autoSelectFamily: true,
|
|
97
99
|
} as https.RequestOptions,
|
|
98
100
|
async httpResponse => {
|
|
101
|
+
if (config?.outHeaders) {
|
|
102
|
+
for (let [key, value] of Object.entries(httpResponse.headers)) {
|
|
103
|
+
config.outHeaders[key] = Array.isArray(value) ? value.join(", ") : value;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
99
107
|
let data: Buffer[] = [];
|
|
100
108
|
httpResponse.on("data", chunk => {
|
|
101
109
|
data.push(chunk);
|
|
@@ -158,6 +166,13 @@ export function httpsRequest(
|
|
|
158
166
|
}
|
|
159
167
|
return new Promise((resolve, reject) => {
|
|
160
168
|
request.onload = () => {
|
|
169
|
+
if (config?.outHeaders) {
|
|
170
|
+
for (let line of request.getAllResponseHeaders().trim().split(/[\r\n]+/)) {
|
|
171
|
+
let index = line.indexOf(":");
|
|
172
|
+
if (index < 0) continue;
|
|
173
|
+
config.outHeaders[line.slice(0, index).trim().toLowerCase()] = line.slice(index + 1).trim();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
161
176
|
if (!request.status.toString().startsWith("2")) {
|
|
162
177
|
try {
|
|
163
178
|
// It should be an error.stack. But if it isn't... just throw the status text...
|