Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
tixfactory.http
Advanced tools
This is just an http module I made for personal use that I decided to make public, don't expect professional grade http requests. This http module is mostly a dummy. It does not yet respect any headers, will not follow redirects, and will not allow setting the follow headers:
Typical installation, and module usage. To install:
$ npm install tixfactory.http
To use:
var http = require("tixfactory.http");
var httpClient = new http.client(); // Everything happens from an individual client
Will auto-handle cookies, and accept-encoding.
var http = require("tixfactory.http");
var httpClient = new http.client();
httpClient.request(object requestData); // Returns promise: .then(function(response){ ... }).catch(function(errors){ ... });
httpClient.get(string url[, object queryParameters]); // Returns http.request preset with url, and queryParameters with method: GET
httpClient.post(string url, buffer requestBody); // Returns http.request with preset url, and requestBody with method: POST
httpClient.socketConfiguration([object configurationOverride]);
httpClient.configuration([object configurationOverride]);
var httpServer = new http.server(port);
{
"url": "https://www.google.com", // Required
"method": "GET", // Required
"queryParameters": {"a": "b"} // Optional
"port": 80, // Optional, will also pull from url or default based on protocol
"isSecure": true, // Optional, will default based on protocol (whether or not to use tls socket)
"requestHeaders": [{name: "Hello", value: "world"}, ...], // Optional, also accepts object: {"Hello": "world"}
"requestBody": Buffer // Optional
"cookieJar": cookieJarObject // Optional - See: https://www.npmjs.com/package/cookiejar
}
{
"statusCode": 400,
"statusText": "Bad Request",
"headers": [{name: "Set-Cookie", value: "wat=who"}, ...],
"body": Buffer,
"contentType": "application/json" // Semi-formatted Content-Type response header (when provided by server)
"responseJson": {"x": "y"}, // Will be available if the contentType is Json, and it can be parsed from JSON.
"responseText": "{\"x\":\"y\"}" // Will be available for some known UTF-8 types.
}
var http = require("tixfactory.http");
var httpClient = new http.client();
httpClient.request({
"method": "GET"
"url": "https://www.roblox.com/profile?userId=48103520"
}).then(function(response){
console.log(response.statusCode, response.statusText);
console.log(response.responseJson);
}).catch(function(errors){
console.error(errors);
});
The same request can also be made with:
var http = require("tixfactory.http");
var httpClient = new http.client();
httpClient.get("https://www.roblox.com/profile", { userId: 48103520 }).then(function(response){
console.log(response.statusCode, response.statusText);
console.log(response.responseJson);
}).catch(function(errors){
console.error(errors);
});
var http = require("tixfactory.http");
var httpClient = new http.client();
var currentConfiguration = httpClient.configuration();
console.log(currentConfiguration);
Configuration object:
{
"cookieJar": cookieJarNpmObject,
"userAgent": "TixFactory.Http (node.js)" // This will be added automatically to any requests that do not have a User-Agent request header. Can be overriden by just setting it.
}
Mostly works like socketConfiguration, may or may not right documentation for this method at some point.
This module allows for some configuration around sockets including throttling and socket limits. To get current configuration settings:
var http = require("tixfactory.http");
var httpClient = new http.client();
var currentConfiguration = httpClient.socketConfiguration();
console.log(currentConfiguration);
Current configuration will look along the lines of:
{
"expiration": 30000, // How long a socket will remain open before closing from inactivity.
"timeoutBetweenQueueProcessing": 50, // If a request is attempting to be made, but all the sockets are in use, and no more can be created: how long to wait before re-checking.
"getWritesPerSecond": function(host, port), // This function should return how many writes per second the module is allowed to make per the arguments. Default returns 1000. MUST return number always.
"getMaxSockets": function(host, port, isSecure) // This is how many sockets are allowed to be open per host (domain), port, and whether or not the socket type is tls. Defaults to 6. MUST return number always.
}
To set configuration:
var http = require("tixfactory.http");
var httpClient = new http.client();
httpClient.socketConfiguration({
getWritesPerSecond: function(host, port){
// example if host is Google, or port is 443 only one request per second is allowed.
if (host === "www.google.com" || port === 443) {
return 1;
}
// otherwise we can make 2 requests per second.
return 2;
}
})
You only have to specify the fields you would like to override. For best results: setting configuration should only be done when the process starts.
TODO: Document better
{
"ip": "127.0.0.1", // The remote IP address
"method": "GET", // The request method
"headers": [{name: "Hello", value: "world"}, ...], // The request headers
"headerMap": {"hello": "world"}, // The request headers in object format (names are all lowercase)
url: {"pathname": "/"}, // [node URL object](https://nodejs.org/api/url.html)
"queryParameters": [{name: "A", value: "b"}, ...], // The query parameters
"queryParameterMap": {"a": "b"}, // The query parameters in object format(names are all lowercase)
"respond": function (response) { ... }, // Returns promise
"body": Buffer, // Will not be included if there is no response body
}
TODO: Document better
{
"statusCode": 200, // The status response code (defaults to 200)
"statusText": "OK", // The status description/text (defaults to [http.STATUS_CODES](https://nodejs.org/api/http.html#http_http_status_codes))
"body": Buffer, // The response buffer
"headers": [{name: "Hello", value: "world"}, ...] // The response headers (can be array or object)
}
TODO: documentation wya?
var http = require("tixfactory.http");
var httpServer = new http.server(80);
httpServer.on("request", function(request){
request.respond({
statusCode: 200,
statusText: "OK",
body: Body.from("Hello, world!"),
headers: [{name: "Hello", value: "world"}]
}).then(function(){
console.log("Sent response!");
}).catch(function(errors){
console.error(errors);
});
});
FAQs
A promised based http module.
The npm package tixfactory.http receives a total of 7 weekly downloads. As such, tixfactory.http popularity was classified as not popular.
We found that tixfactory.http demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.