New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

http-range

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-range

Node.js parser for Content-Range and Range HTTP/1.1 header fields.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.2K
increased by16.4%
Maintainers
1
Weekly downloads
 
Created
Source

http-range

Node.js parser for Content-Range and Range HTTP header fields according to the HTTP/1.1 specifications.

Build Status

Installation

$ npm install http-range

Usage

var ContentRange = require('http-range').ContentRange;
var Range = require('http-range').Range;

// Parsing and creating 'Content-Range' header
ContentRange.prototype.parse('bytes 0-49/50');  // Content-Range: bytes 0-49/50
new ContentRange('bytes', '0-49', 50).toString(); // => bytes 0-49/50

// Parsing and creating 'Range' header
Range.prototype.parse('bytes=0-49');  // Range: bytes=0-49
new Range('bytes', '0-49'); // => bytes=0-49

For more usages check the test files.

API

ContentRange Class

new ContentRange(unit, range, length)
  • unit {String} Usually 'bytes', but can be any token
  • range {RangeSpec|String} A RangeSpec instance, a string like '0-49' or '*' if unknown
  • length {Number|'*'} The total length of the full entity-body or '*' if this length is unknown or difficult to determine

Throws error if arguments are invalid.

Properties
  • unit {String}
  • range {RangeSpec}
  • length {Number|null} Null if unknown
Methods
  • toString() Return a valid string value
  • parse(input) Parse an input string. Throws error if invalid
Allowed Content-Range(s)
  • Content-Range: bytes 0-49/50
  • Content-Range: bytes 0-49/*
  • Content-Range: bytes */50
  • Content-Range: bytes */*

Range Class

new Range(unit, ranges)
  • unit {String} Usually 'bytes', but can be any token
  • ranges {RangeSpec[]|String} An array of RangeSpec instances or a string like '0-49[,50-99][...]'

Throws error if arguments are invalid.

Properties
Methods
  • toString() Return a valid string value
  • parse(input) Parse an input string. Throws error if invalid
Allowed Range(s)
  • Range: bytes=0-49
  • Range: bytes=0-49,50-99,-30
  • Range: bytes=1-
  • Range: bytes=-50

RangeSpec Class

new RangeSpec(low, high, size)
  • low {Number|undefined}
  • high {Number|undefined}
  • size {Number|undefined} For validation only, optional

Throws error if arguments are invalid.

Properties
  • low {Number|undefined}
  • high {Number|undefined}
Methods
  • toString() Return a valid string value
  • parse(input) Parse an input string. Throws error if invalid
Examples of valid ranges
  • *
  • 0-49
  • -49
  • 34-

Tests

$ make test

Keywords

FAQs

Package last updated on 28 Feb 2015

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