@jongleberry/vurst-markdown 0.2.3 → 0.2.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jongleberry/vurst-markdown",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Rust + N-API: Markdown chunking and rendering.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -238,10 +238,7 @@ function request(url, handleResponse, baseUrl, redirects = 0) {
238
238
  return new Promise((resolve, reject) => {
239
239
  const client = url.startsWith("http://") ? http : https;
240
240
  const proxyUrl = proxyUrlFor(url);
241
- const requestOptions = proxyUrl
242
- ? { agent: new HttpsProxyAgent(proxyUrl) }
243
- : undefined;
244
- const req = client.get(url, requestOptions, (response) => {
241
+ const onResponse = (response) => {
245
242
  if ([301, 302, 303, 307, 308].includes(response.statusCode)) {
246
243
  response.resume();
247
244
  if (redirects >= MAX_REDIRECTS) {
@@ -265,7 +262,10 @@ function request(url, handleResponse, baseUrl, redirects = 0) {
265
262
  return;
266
263
  }
267
264
  Promise.resolve(handleResponse(response)).then(resolve, reject);
268
- });
265
+ };
266
+ const req = proxyUrl
267
+ ? client.get(url, { agent: new HttpsProxyAgent(proxyUrl) }, onResponse)
268
+ : client.get(url, onResponse);
269
269
  req.setTimeout(DOWNLOAD_TIMEOUT_MS, () => {
270
270
  const error = new Error(`Download timed out after ${DOWNLOAD_TIMEOUT_MS}ms`);
271
271
  error.retryable = true;