Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@huksley/request

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@huksley/request - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

3

package.json
{
"name": "@huksley/request",
"version": "1.0.1",
"version": "1.0.2",
"description": "[gist-sized] Zero dependency, single-file NodeJS 14+ HTTP(s) request module",
"main": "request.js",
"type": "module",
"repository": "https://github.com/huksley/node-request",

@@ -7,0 +8,0 @@ "bugs": "https://github.com/huksley/node-request/issues",

@@ -11,4 +11,5 @@ # HTTP(s) Request

const res = await request("https://jsonip.com");
console.info("Your IP", res.body.ip, "headers", res.headers);
request("https://jsonip.com").then((res) => {
console.info("Your IP", res.body.ip, "headers", res.headers);
});
```

@@ -15,0 +16,0 @@

import { request as httpsRequest } from "https";
import { IncomingMessage, request as httpRequest } from "http";
import * as zlib from "zlib";
import { inspect } from "util";
/**
* Makes HTTP(s) request and returns response with parsed body.
*
* Makes HTTP(s) request and returns response with parsed body.
*
* ```

@@ -31,3 +32,3 @@ * const res = await request("https://jsonip.com")

servername: u.host,
rejectUnauthorized: options.rejectUnauthorized || true,
rejectUnauthorized: options?.rejectUnauthorized || true,
method: method || "GET",

@@ -56,6 +57,12 @@ encoding: encoding !== undefined ? null : encoding,

res.on("data", (chunk) => (data = Buffer.concat([data, chunk])));
res.on("error", (err) => {
const e = new Error("HTTP request failed: " + url);
e.error = err;
reject(e);
res.on("error", (e) => {
const err = new Error("HTTP request failed: " + url);
err.cause = e;
// Add properties but disallow too verbose dumping
res[inspect.custom] = () => {
return "**Response**";
};
// This disallows dump of response in error log and in
Object.defineProperty(err, "response", { enumerable: true, get: () => res });
reject(err);
});

@@ -79,7 +86,12 @@

"end",
handler((err, data) => {
if (err) {
const e = new Error("HTTP request failed: " + url);
e.error = err;
reject(e);
handler((e, data) => {
if (e) {
const err = new Error("HTTP request failed: " + url);
err.cause = e;
// Add properties but disallow too verbose dumping
res[inspect.custom] = () => {
return "**Response**";
};
Object.defineProperty(err, "response", { enumerable: true, get: () => res });
reject(err);
return;

@@ -98,6 +110,11 @@ }

}
} catch (err) {
const e = new Error("HTTP request failed: " + url);
e.error = err;
reject(e);
} catch (e) {
const err = new Error("HTTP request failed: " + url);
err.cause = e;
// Add properties but disallow too verbose dumping
res[inspect.custom] = () => {
return "**Response**";
};
Object.defineProperty(err, "response", { enumerable: true, get: () => res });
reject(err);
}

@@ -109,7 +126,11 @@

if (verbose) {
console.info("HTTP request failed", url, res.statusCode, data);
console.info("HTTP request failed", url, res.statusCode);
}
const err = new Error("HTTP request failed: " + url);
err.statusCode = res.statusCode;
err.response = res;
// Add properties but disallow too verbose dumping
res[inspect.custom] = () => {
return "**Response**";
};
Object.defineProperty(err, "response", { enumerable: true, get: () => res });
reject(err);

@@ -116,0 +137,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc