
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
http-response-object
Advanced tools
The http-response-object npm package is a utility for creating and manipulating HTTP response objects. It provides a simple and consistent API for generating HTTP responses, making it easier to handle HTTP responses in Node.js applications.
Creating a Response Object
This feature allows you to create a new HTTP response object with a specified status code, headers, and body. In this example, a response object with a 200 status code, JSON content type, and a JSON body is created.
const Response = require('http-response-object');
const response = new Response(200, { 'Content-Type': 'application/json' }, JSON.stringify({ message: 'Success' }));
console.log(response);
Accessing Response Properties
This feature allows you to access the properties of the response object, such as statusCode, headers, and body. The example demonstrates how to log these properties to the console.
const Response = require('http-response-object');
const response = new Response(200, { 'Content-Type': 'application/json' }, JSON.stringify({ message: 'Success' }));
console.log(response.statusCode); // 200
console.log(response.headers); // { 'Content-Type': 'application/json' }
console.log(response.body); // {"message":"Success"}
Modifying Response Headers
This feature allows you to modify the headers of an existing response object. In this example, a custom header is added to the response headers.
const Response = require('http-response-object');
let response = new Response(200, { 'Content-Type': 'application/json' }, JSON.stringify({ message: 'Success' }));
response.headers['X-Custom-Header'] = 'CustomValue';
console.log(response.headers); // { 'Content-Type': 'application/json', 'X-Custom-Header': 'CustomValue' }
Express is a fast, unopinionated, minimalist web framework for Node.js. It provides robust features for building web and mobile applications, including handling HTTP requests and responses. Unlike http-response-object, Express is a full-fledged web framework with routing, middleware support, and more.
Axios is a promise-based HTTP client for the browser and Node.js. It provides a simple API for making HTTP requests and handling responses. While axios focuses on making HTTP requests, http-response-object is specifically designed for creating and manipulating HTTP response objects.
Node-fetch is a lightweight module that brings window.fetch to Node.js. It allows you to make HTTP requests and handle responses in a similar way to the Fetch API in the browser. Unlike http-response-object, node-fetch is primarily used for making HTTP requests rather than creating response objects.
A simple object to represent an http response (with flow and typescript types)
npm install http-response-object
var Response = require('http-response-object');
var res = new Response(200, {}, new Buffer('A ok'), 'http://example.com');
//res.statusCode === 200
//res.headers === {}
//res.body === new Buffer('A ok')
//res.url === 'http://example.com'
res.getBody();
// => new Buffer('A ok')
var res = new Response(404, {'Header': 'value'}, new Buffer('Wheres this page'), 'http://example.com');
//res.statusCode === 404
//res.headers === {header: 'value'}
//res.body === new Buffer('Wheres this page')
//res.url === 'http://example.com'
res.getBody();
// => throws error with `statusCode`, `headers`, `body` and `url` properties copied from the response
statusCode
: Number - the status code of the responseheaders
: Object - the headers of the response. The keys are automatically made lower case.body
: Buffer | String - the body of the response. Should be a buffer on the server side, but may be a simple string for lighter weight clients.url
: String - the url that was requested. If there were redirects, this should be the last url to get requested.MIT
FAQs
A simple object to represent an http response
The npm package http-response-object receives a total of 681,448 weekly downloads. As such, http-response-object popularity was classified as popular.
We found that http-response-object 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
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.