@uoa/lambda-tracing 2.3.0-beta.1 → 2.3.0
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/dist/uoaHttps.js +11 -9
- package/package.json +1 -1
- package/uoaHttps.ts +11 -9
package/dist/uoaHttps.js
CHANGED
|
@@ -110,15 +110,16 @@ function doHttpsRequest(options, resolve, reject) {
|
|
|
110
110
|
try {
|
|
111
111
|
let body = Buffer.concat(chunks);
|
|
112
112
|
let parsedBody = body.toString();
|
|
113
|
+
let decodedBody = body;
|
|
113
114
|
//Get the response content-encoding header value so we can decode before parsing
|
|
114
115
|
const responseContentEncoding = response.headers["content-encoding"]?.toLowerCase() ?? '';
|
|
115
116
|
if (responseContentEncoding !== '') {
|
|
116
|
-
|
|
117
|
+
decodedBody = decodeResponse(body, responseContentEncoding);
|
|
117
118
|
}
|
|
118
119
|
//Get the response content-type header value so we can apply different parsing methods
|
|
119
120
|
const responseContentType = response.headers["content-type"]?.toLowerCase() ?? '';
|
|
120
121
|
if (responseContentType === '' || responseContentType.includes('json')) {
|
|
121
|
-
parsedBody = JSON.parse(
|
|
122
|
+
parsedBody = JSON.parse(decodedBody.toString());
|
|
122
123
|
}
|
|
123
124
|
else if (responseContentType.includes('xml')) {
|
|
124
125
|
const parser = new fast_xml_parser_1.XMLParser({
|
|
@@ -126,10 +127,10 @@ function doHttpsRequest(options, resolve, reject) {
|
|
|
126
127
|
ignorePiTags: true,
|
|
127
128
|
ignoreAttributes: false
|
|
128
129
|
});
|
|
129
|
-
parsedBody = parser.parse(
|
|
130
|
+
parsedBody = parser.parse(decodedBody.toString());
|
|
130
131
|
}
|
|
131
132
|
else if (responseContentType.includes('image')) {
|
|
132
|
-
parsedBody =
|
|
133
|
+
parsedBody = decodedBody.toString('base64');
|
|
133
134
|
}
|
|
134
135
|
if (response.statusCode !== undefined && response.statusCode >= 200 && response.statusCode < 300) {
|
|
135
136
|
resolve(parsedBody);
|
|
@@ -161,22 +162,23 @@ function setRequestBody(request, data) {
|
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
164
|
}
|
|
164
|
-
function decodeResponse(
|
|
165
|
+
function decodeResponse(encodedBody, contentEncodingHeader) {
|
|
165
166
|
const contentEncodings = contentEncodingHeader.replace(/\s/g, '').split(',');
|
|
167
|
+
let decodedBody = encodedBody;
|
|
166
168
|
contentEncodings.forEach(contentEncoding => {
|
|
167
169
|
switch (contentEncoding) {
|
|
168
170
|
case 'gzip':
|
|
169
|
-
|
|
171
|
+
decodedBody = zlib.gunzipSync(decodedBody);
|
|
170
172
|
break;
|
|
171
173
|
case 'deflate':
|
|
172
|
-
|
|
174
|
+
decodedBody = zlib.inflateSync(decodedBody);
|
|
173
175
|
break;
|
|
174
176
|
case 'br':
|
|
175
|
-
|
|
177
|
+
decodedBody = zlib.brotliDecompressSync(decodedBody);
|
|
176
178
|
break;
|
|
177
179
|
}
|
|
178
180
|
});
|
|
179
|
-
return
|
|
181
|
+
return decodedBody;
|
|
180
182
|
}
|
|
181
183
|
module.exports = {
|
|
182
184
|
request,
|
package/package.json
CHANGED
package/uoaHttps.ts
CHANGED
|
@@ -101,26 +101,27 @@ function doHttpsRequest(options: RequestOptions, resolve: any, reject: any): Cli
|
|
|
101
101
|
try {
|
|
102
102
|
let body: Buffer = Buffer.concat(chunks);
|
|
103
103
|
let parsedBody: any = body.toString();
|
|
104
|
+
let decodedBody: Buffer = body;
|
|
104
105
|
|
|
105
106
|
//Get the response content-encoding header value so we can decode before parsing
|
|
106
107
|
const responseContentEncoding: string = response.headers["content-encoding"]?.toLowerCase() ?? '';
|
|
107
108
|
if (responseContentEncoding !== '') {
|
|
108
|
-
|
|
109
|
+
decodedBody = decodeResponse(body, responseContentEncoding);
|
|
109
110
|
}
|
|
110
111
|
|
|
111
112
|
//Get the response content-type header value so we can apply different parsing methods
|
|
112
113
|
const responseContentType: string = response.headers["content-type"]?.toLowerCase() ?? '';
|
|
113
114
|
if (responseContentType === '' || responseContentType.includes('json')) {
|
|
114
|
-
parsedBody = JSON.parse(
|
|
115
|
+
parsedBody = JSON.parse(decodedBody.toString());
|
|
115
116
|
} else if (responseContentType.includes('xml')) {
|
|
116
117
|
const parser = new XMLParser({
|
|
117
118
|
ignoreDeclaration: true,
|
|
118
119
|
ignorePiTags: true,
|
|
119
120
|
ignoreAttributes: false
|
|
120
121
|
});
|
|
121
|
-
parsedBody = parser.parse(
|
|
122
|
+
parsedBody = parser.parse(decodedBody.toString());
|
|
122
123
|
} else if (responseContentType.includes('image')) {
|
|
123
|
-
parsedBody =
|
|
124
|
+
parsedBody = decodedBody.toString('base64');
|
|
124
125
|
}
|
|
125
126
|
|
|
126
127
|
if (response.statusCode !== undefined && response.statusCode >= 200 && response.statusCode < 300) {
|
|
@@ -153,22 +154,23 @@ function setRequestBody(request: ClientRequest, data: any) {
|
|
|
153
154
|
}
|
|
154
155
|
}
|
|
155
156
|
|
|
156
|
-
function decodeResponse(
|
|
157
|
+
function decodeResponse(encodedBody: Buffer, contentEncodingHeader: string): Buffer {
|
|
157
158
|
const contentEncodings: string[] = contentEncodingHeader.replace(/\s/g, '').split(',');
|
|
159
|
+
let decodedBody: Buffer = encodedBody;
|
|
158
160
|
contentEncodings.forEach(contentEncoding => {
|
|
159
161
|
switch (contentEncoding) {
|
|
160
162
|
case 'gzip':
|
|
161
|
-
|
|
163
|
+
decodedBody = zlib.gunzipSync(decodedBody);
|
|
162
164
|
break;
|
|
163
165
|
case 'deflate':
|
|
164
|
-
|
|
166
|
+
decodedBody = zlib.inflateSync(decodedBody);
|
|
165
167
|
break;
|
|
166
168
|
case 'br':
|
|
167
|
-
|
|
169
|
+
decodedBody = zlib.brotliDecompressSync(decodedBody);
|
|
168
170
|
break;
|
|
169
171
|
}
|
|
170
172
|
});
|
|
171
|
-
return
|
|
173
|
+
return decodedBody;
|
|
172
174
|
}
|
|
173
175
|
|
|
174
176
|
module.exports = {
|