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

@hqoss/http-client

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hqoss/http-client - npm Package Compare versions

Comparing version 0.1.15-0 to 0.1.16-0

68

dist/lib/httpClient/httpClient.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require("events");
const http_1 = require("http");

@@ -24,3 +23,2 @@ const stream_1 = require("stream");

}
const resolver = new events_1.EventEmitter();
const url = this.buildUrl(pathOrUrl);

@@ -39,25 +37,14 @@ const contentLength = getContentLength(data);

telemetry === null || telemetry === void 0 ? void 0 : telemetry.emit(telemetry_1.EventType.RequestStreamInitialised, new telemetry_1.TelemetryEvent(telemetry_1.EventType.RequestStreamInitialised, { url, opts }));
req.once("socket", (socket) => {
telemetry === null || telemetry === void 0 ? void 0 : telemetry.emit(telemetry_1.EventType.SocketObtained, new telemetry_1.TelemetryEvent(telemetry_1.EventType.SocketObtained));
socket.once("connect", () => {
telemetry === null || telemetry === void 0 ? void 0 : telemetry.emit(telemetry_1.EventType.ConnectionEstablished, new telemetry_1.TelemetryEvent(telemetry_1.EventType.ConnectionEstablished));
return new Promise((resolve, reject) => {
req.once("socket", (socket) => {
telemetry === null || telemetry === void 0 ? void 0 : telemetry.emit(telemetry_1.EventType.SocketObtained, new telemetry_1.TelemetryEvent(telemetry_1.EventType.SocketObtained));
socket.once("connect", () => {
telemetry === null || telemetry === void 0 ? void 0 : telemetry.emit(telemetry_1.EventType.ConnectionEstablished, new telemetry_1.TelemetryEvent(telemetry_1.EventType.ConnectionEstablished));
});
});
});
req.once("response", (res) => {
telemetry === null || telemetry === void 0 ? void 0 : telemetry.emit(telemetry_1.EventType.ResponseStreamReceived, new telemetry_1.TelemetryEvent(telemetry_1.EventType.ResponseStreamReceived));
resolver.emit("resolve", res);
});
req.once("error", (error) => {
// See https://nodejs.org/api/http.html#http_request_destroy_error
//
// No further events will be emitted.
// All listeners will be removed once the request is garbage collected.
// Remaining data in the response will be dropped and the socket will be destroyed.
req.destroy();
telemetry === null || telemetry === void 0 ? void 0 : telemetry.emit(telemetry_1.EventType.RequestError, new telemetry_1.TelemetryEvent(telemetry_1.EventType.RequestError, undefined, error));
resolver.emit("reject", error);
});
if (data instanceof stream_1.Readable) {
// If there is an error reading data, destroy the request and pass the error.
data.once("error", (error) => {
req.once("response", (res) => {
telemetry === null || telemetry === void 0 ? void 0 : telemetry.emit(telemetry_1.EventType.ResponseStreamReceived, new telemetry_1.TelemetryEvent(telemetry_1.EventType.ResponseStreamReceived));
resolve(res);
});
req.once("error", (error) => {
// See https://nodejs.org/api/http.html#http_request_destroy_error

@@ -68,15 +55,24 @@ //

// Remaining data in the response will be dropped and the socket will be destroyed.
req.destroy(error);
req.destroy();
telemetry === null || telemetry === void 0 ? void 0 : telemetry.emit(telemetry_1.EventType.RequestError, new telemetry_1.TelemetryEvent(telemetry_1.EventType.RequestError, undefined, error));
reject(error);
});
// Pipe ends the writable stream (req) implicitly.
// See https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options.
data.pipe(req);
}
else {
req.end(data);
}
telemetry === null || telemetry === void 0 ? void 0 : telemetry.emit(telemetry_1.EventType.RequestStreamEnded, new telemetry_1.TelemetryEvent(telemetry_1.EventType.RequestStreamEnded));
return new Promise((resolve, reject) => {
resolver.once("resolve", resolve);
resolver.once("reject", reject);
if (data instanceof stream_1.Readable) {
// If there is an error reading data, destroy the request and pass the error.
data.once("error", (error) => {
// See https://nodejs.org/api/http.html#http_request_destroy_error
//
// No further events will be emitted.
// All listeners will be removed once the request is garbage collected.
// Remaining data in the response will be dropped and the socket will be destroyed.
req.destroy(error);
});
// Pipe ends the writable stream (req) implicitly.
// See https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options.
data.pipe(req);
}
else {
req.end(data);
}
telemetry === null || telemetry === void 0 ? void 0 : telemetry.emit(telemetry_1.EventType.RequestStreamEnded, new telemetry_1.TelemetryEvent(telemetry_1.EventType.RequestStreamEnded));
});

@@ -83,0 +79,0 @@ };

@@ -79,3 +79,2 @@ import { EventEmitter } from "events";

const resolver = new EventEmitter();
const url = this.buildUrl(pathOrUrl);

@@ -102,44 +101,27 @@ const contentLength = getContentLength(data);

req.once("socket", (socket) => {
telemetry?.emit(
EventType.SocketObtained,
new TelemetryEvent(EventType.SocketObtained),
);
socket.once("connect", () => {
return new Promise((resolve, reject) => {
req.once("socket", (socket) => {
telemetry?.emit(
EventType.ConnectionEstablished,
new TelemetryEvent(EventType.ConnectionEstablished),
EventType.SocketObtained,
new TelemetryEvent(EventType.SocketObtained),
);
socket.once("connect", () => {
telemetry?.emit(
EventType.ConnectionEstablished,
new TelemetryEvent(EventType.ConnectionEstablished),
);
});
});
});
req.once("response", (res) => {
telemetry?.emit(
EventType.ResponseStreamReceived,
new TelemetryEvent(EventType.ResponseStreamReceived),
);
req.once("response", (res) => {
telemetry?.emit(
EventType.ResponseStreamReceived,
new TelemetryEvent(EventType.ResponseStreamReceived),
);
resolver.emit("resolve", res);
});
resolve(res);
});
req.once("error", (error) => {
// See https://nodejs.org/api/http.html#http_request_destroy_error
//
// No further events will be emitted.
// All listeners will be removed once the request is garbage collected.
// Remaining data in the response will be dropped and the socket will be destroyed.
req.destroy();
telemetry?.emit(
EventType.RequestError,
new TelemetryEvent(EventType.RequestError, undefined, error),
);
resolver.emit("reject", error);
});
if (data instanceof Readable) {
// If there is an error reading data, destroy the request and pass the error.
data.once("error", (error) => {
req.once("error", (error) => {
// See https://nodejs.org/api/http.html#http_request_destroy_error

@@ -150,20 +132,34 @@ //

// Remaining data in the response will be dropped and the socket will be destroyed.
req.destroy(error);
req.destroy();
telemetry?.emit(
EventType.RequestError,
new TelemetryEvent(EventType.RequestError, undefined, error),
);
reject(error);
});
// Pipe ends the writable stream (req) implicitly.
// See https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options.
data.pipe(req);
} else {
req.end(data);
}
if (data instanceof Readable) {
// If there is an error reading data, destroy the request and pass the error.
data.once("error", (error) => {
// See https://nodejs.org/api/http.html#http_request_destroy_error
//
// No further events will be emitted.
// All listeners will be removed once the request is garbage collected.
// Remaining data in the response will be dropped and the socket will be destroyed.
req.destroy(error);
});
telemetry?.emit(
EventType.RequestStreamEnded,
new TelemetryEvent(EventType.RequestStreamEnded),
);
// Pipe ends the writable stream (req) implicitly.
// See https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options.
data.pipe(req);
} else {
req.end(data);
}
return new Promise((resolve, reject) => {
resolver.once("resolve", resolve);
resolver.once("reject", reject);
telemetry?.emit(
EventType.RequestStreamEnded,
new TelemetryEvent(EventType.RequestStreamEnded),
);
});

@@ -170,0 +166,0 @@ };

{
"name": "@hqoss/http-client",
"version": "0.1.15-0",
"version": "0.1.16-0",
"description": "A light-weight, performant, composable blueprint for writing consistent and re-usable Node.js HTTP clients",

@@ -5,0 +5,0 @@ "main": "./dist/lib/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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