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

merge-headers

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

merge-headers

Easily merge HTTP headers

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
342
decreased by-17.59%
Maintainers
1
Weekly downloads
 
Created
Source

merge-headers

Easily merge HTTP headers

merge-headers is a utility function that merges all your headers (plain objects, Headers instances or in Arrays format) and gives you the possibility to remove specific headers without too much headache.

Usage

import mergeHeaders from 'merge-headers';

const oldHeaders = new Headers({
    'Content-Type': 'text/xml',
    'Authorization': 'basic'
});

// Remove `Authorization` header without altering `oldHeaders`
const newHeaders = mergeHeaders(oldHeaders, {
    'Authorization': undefined
});

console.log(newHeaders.has('Authorization'));
// => false

// Or just merge two headers object
const headers = mergeHeaders(oldHeaders, {
    'rainbow': 'rainbow'
});

console.log(headers.has('Autorization'));
// => true

console.log(headers.has('rainbow'));
// => true

API

mergeHeaders(...sources)

The sources are the same as what the Headers constructor can take.

A TypeError will be thrown if sources contains something else than an object.

Returns a Headers object.

Why?

This is mostly for convenience. It is much easier to do mergeHeaders() instead of deleting them one by one, thus mutating your headers instance. This way you create a new one with the exact headers you want.

Roadmap

  • Tests
  • Usage
  • Advanced use cases

Keywords

FAQs

Package last updated on 28 Sep 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