Socket
Socket
Sign inDemoInstall

structured-headers

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    structured-headers

Implementation of draft-ietf-httpbis-header-structure, structured headers for HTTP.


Version published
Maintainers
1
Install size
23.3 kB
Created

Readme

Source

Structured Headers parser for Javascript

This library is a parser for the structured headers specification. Currently it's still a draft, so this package is also in alpha until the specification stabilizes as a RFC.

Installation

Using npm:

npm install structured-headers

API

Parsing an item

The following are examples of item headers:

Parsed as string

# Parsed into string
Header: "foo"
Header: bar

# Parsed into number
Header: 5
Header: -10
Header: 5.01415

# Parsed into boolean
Header: ?T
Header: ?F

To parse these header values, use parseItem:

const sh = require('structured-headers');
console.log(sh.parseItem(header));

Parsing a list

Lists contain items separated by comma Here's an example

Header: 5, "foo", bar, ?T

To parse these:

const sh = require('structured-headers');
console.log(sh.parseList(header));

This will result in [5, "foo", "bar", true].

Parsing a dictionary

A dictionary is a key->value object. Examples:

Example: foo: "Bar"; baz: 5

Dictionary keys can be any item. This is parsed with:

const sh = require('structured-headers');
console.log(sh.parseDictionary(header));

The output for this is an object: { foo: 'bar', baz: 5}.

Parsing a list of lists

A list of list is a 2-dimensional array. The top level is separated by commas, and the second level is separated by semi-colons.

Every member in this list can be any item (string, boolean, number).

Example: "foo";"bar", "baz", "bat"; "one"

Parsing:

const sh = require('structured-headers');
console.log(sh.parseListList(header));

This will result in [['foo', 'bar'], ['baz'], ['bat', 'one']].

Parsing a parameterized list

A parameterized list is a list for which every member can have one or more parameters, specified as a dictionary.

ExampleParamList: foo; param1: "value1", bar; "param2": "value2"

Parsing:

const sh = require('structured-headers');
console.log(sh.parseParamList(header));

This will result in [['foo', { param1: "value1" }], ['bar', { param2: "value2" }].

Browser support

There is a minified version of this library in the browser/ directory. This minified file will expose a global variable called 'structuredHeader' which contains the rest of the api.

Keywords

FAQs

Last updated on 06 Dec 2018

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc