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

header-generator

Package Overview
Dependencies
Maintainers
2
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

header-generator

NodeJs package for generating browser-like headers.

  • 0.0.1-beta.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
67K
decreased by-0.41%
Maintainers
2
Weekly downloads
 
Created
Source

Header generator

NodeJs package for generating browser-like headers.

  • Installation
  • Usage
  • Result example
  • API Reference

Installation

Run the npm install header-generator command. No further setup is needed afterwards.

Usage

To use the generator, you need to create an instance of the HeaderGenerator class which is exported from this package. Constructor of this class accepts a HeaderGeneratorOptions object, which can be used to globally specify what kind of headers you are looking for:

const HeaderGenerator = require('header-generator');
let headerGenerator = new HeaderGenerator({
        browsers: [
            {name: "firefox", minVersion: 80},
            {name: "chrome", minVersion: 87},
        ],
        devices: [
            "desktop"
        ],
        operatingSystems: [
            "windows"
        ]
});

You can then get the headers using the getHeaders method, either with no argument, or with another HeaderGeneratorOptions object, this time specifying the options only for this call (overwriting the global options when in conflict) and using the global options specified beforehands for the unspecified options:

let headers = headersGenerator.getHeaders({
        operatingSystems: [
            "linux"
        ],
        locales: ["en-US", "en"]
});

This method always generates a random realistic set of headers, excluding the request dependant headers, which need to be filled in afterwards. Since the generation is randomized, multiple calls to this method with the same parameters can generate multiple different outputs.

Result example

A result that can be generated for the usage example above:

{
  "sec-ch-ua-mobile": "?0",
  "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36",
  "accept-encoding": "gzip, deflate, br",
  "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
  "upgrade-insecure-requests": "1",
  "accept-language": "en-US,en;0.9",
  "sec-fetch-site": "same-site",
  "sec-fetch-mode": "navigate",
  "sec-fetch-user": "?1",
  "sec-fetch-dest": "document"
}

API Reference

All public classes, methods and their parameters can be inspected in this API reference.

HeaderGenerator

HeaderGenerator randomly generates realistic browser headers based on specified options.


new HeaderGenerator(options)
ParamTypeDescription
optionsHeaderGeneratorOptionsdefault header generation options used unless overridden

headerGenerator.getHeaders(options, requestDependentHeaders)

Generates a single set of headers using a combination of the default options specified in the constructor and their possible overrides provided here.

ParamTypeDescription
optionsHeaderGeneratorOptionsspecifies options that should be overridden for this one call
requestDependentHeadersObjectspecifies known values of headers dependent on the particular request

BrowserSpecification

ParamTypeDescription
namestringOne of chrome, firefox and safari.
minVersionnumberMinimal version of browser used.
maxVersionnumberMaximal version of browser used.
httpVersionstringHttp version to be used to generate headers (the headers differ depending on the version). Either 1 or 2. If none specified the httpVersion specified in HeaderGeneratorOptions is used.

HeaderGeneratorOptions

ParamTypeDescription
browsersArray.<BrowserSpecification>List of BrowserSpecifications to generate the headers for.
operatingSystemsArray.<string>List of operating systems to generate the headers for. The options are windows, macos, linux, android and ios.
devicesArray.<string>List of devices to generate the headers for. Options are desktop and mobile.
localesArray.<string>List of at most 10 languages to include in the Accept-Language request header in the language format accepted by that header, for example en, en-US or de.
httpVersionstringHttp version to be used to generate headers (the headers differ depending on the version). Can be either 1 or 2. Default value is 2.

FAQs

Package last updated on 28 Apr 2021

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

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