🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

http-deceiver

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-deceiver

Deceive HTTP parser

1.2.7
latest
Version published
Weekly downloads
11M
-13.53%
Maintainers
1
Weekly downloads
 
Created

What is http-deceiver?

The http-deceiver npm package is designed to manipulate HTTP requests and responses. It allows developers to intercept, modify, and create custom behaviors for HTTP traffic, which is particularly useful in testing and development environments where simulating various network conditions and responses is necessary.

What are http-deceiver's main functionalities?

Intercept and modify HTTP requests

This feature allows you to intercept HTTP requests and modify properties such as the URL before the server processes them. In the provided code, the request URL is changed to '/modified-path', and a custom response is sent back.

const httpDeceiver = require('http-deceiver');
const http = require('http');

const server = http.createServer((req, res) => {
  httpDeceiver.deceive(req, res, (req, res) => {
    req.url = '/modified-path';
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Request was modified');
  });
});

server.listen(3000);

Simulate server responses

This feature is useful for simulating different server responses under various conditions. In this example, a 503 Service Unavailable response is simulated regardless of the actual server state or the incoming request.

const httpDeceiver = require('http-deceiver');
const http = require('http');

const server = http.createServer((req, res) => {
  httpDeceiver.deceive(req, res, (req, res) => {
    res.writeHead(503, {'Content-Type': 'text/plain'});
    res.end('Service Unavailable');
  });
});

server.listen(3000);

Other packages similar to http-deceiver

FAQs

Package last updated on 17 May 2016

Did you know?

Socket

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.

Install

Related posts