com.jimuwd.xian.registry-proxy 1.0.87 → 1.0.88
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/index.js +8 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -154,7 +154,13 @@ async function fetchFromRegistry(registry, targetUrl, reqFromDownstreamClient, l
|
|
|
154
154
|
mergedHeaders.host = upstreamHost;
|
|
155
155
|
}
|
|
156
156
|
const response = await fetch(targetUrl, { headers: mergedHeaders });
|
|
157
|
-
logger.info(`
|
|
157
|
+
logger.info(`
|
|
158
|
+
Response from upstream ${targetUrl}: ${response.status} ${response.statusText}
|
|
159
|
+
content-type=${response.headers.get('content-type')}
|
|
160
|
+
content-encoding=${response.headers.get('content-encoding')}
|
|
161
|
+
content-length=${response.headers.get('content-length')}
|
|
162
|
+
transfer-encoding=${response.headers.get('transfer-encoding')}
|
|
163
|
+
`);
|
|
158
164
|
return response.ok ? response : null;
|
|
159
165
|
}
|
|
160
166
|
catch (e) {
|
|
@@ -172,12 +178,6 @@ async function fetchFromRegistry(registry, targetUrl, reqFromDownstreamClient, l
|
|
|
172
178
|
limiter.release();
|
|
173
179
|
}
|
|
174
180
|
}
|
|
175
|
-
function resetHeaderContentLengthIfTransferEncodingIsAbsent(safeHeaders, targetUrl, bodyData) {
|
|
176
|
-
if (!safeHeaders["transfer-encoding"]) {
|
|
177
|
-
logger.info(`Transfer-Encoding header is absent, then set the content-length header, upstream url is ${targetUrl}`);
|
|
178
|
-
safeHeaders["content-length"] = Buffer.byteLength(bodyData);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
181
|
async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDownstreamClient, upstreamResponse, reqFromDownstreamClient, proxyInfo, proxyPort, registryInfos) {
|
|
182
182
|
if (!upstreamResponse.ok)
|
|
183
183
|
throw new Error("Only 2xx upstream response is supported");
|
|
@@ -199,7 +199,7 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
const bodyData = JSON.stringify(data);
|
|
202
|
-
const safeHeaders = { 'content-type':
|
|
202
|
+
const safeHeaders = { 'content-type': contentType, 'content-length': Buffer.byteLength(bodyData) };
|
|
203
203
|
logger.info(`Response to downstream client headers`, JSON.stringify(safeHeaders), targetUrl);
|
|
204
204
|
resToDownstreamClient.writeHead(upstreamResponse.status, { 'content-type': 'application/json' }).end(bodyData);
|
|
205
205
|
}
|