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

http-z

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-z

HTTP message parser and builder

8.1.1
latest
Source
npm
Version published
Weekly downloads
39K
1.69%
Maintainers
1
Weekly downloads
 
Created
Source

http-z

HTTP message (request/response) parser/builder according to the rules defined in RFC 7230

Works in Node.js and in the browser, has zero dependencies.

Build Status Code Coverage License npm version

Demo

Contents

Install

$ pnpm i http-z

Usage

import { parse, build } from 'http-z'

const plainMessage = [
  'GET /features?p1=v1 HTTP/1.1',
  'Host: example.com',
  'Accept: *',
  'Accept-Encoding: gzip,deflate',
  'Accept-Language: en-US;q=0.6, en;q=0.4',
  '',
  ''
].join('\r\n')

const messageModel = parse(plainMessage)
console.log(messageModel)

/* output:
{
  "method": "GET",
  "protocolVersion": "HTTP/1.1",
  "host": "example.com",
  "target": "/features?p1=v1",
  "path": "/features",
  "queryParams": [
    { "name": "p1", "value": "v1" }
  ],
  "headers": [
    { "name": "Host", "value": "example.com" },
    { "name": "Accept", value": "*" },
    { "name": "Accept-Encoding", "value": "gzip,deflate" },
    { "name": "Accept-Language", "value": "en-US;q=0.6, en;q=0.4" }
  ],
  "headersSize": 135,
  "bodySize": 0
}
*/

const plainMessageParsed = build(messageModel)
console.log(plainMessageParsed)

/* output:
GET /features?p1=v1 HTTP/1.1
Host: example.com
Accept: *
Accept-Encoding: gzip,deflate
Accept-Language: en-US;q=0.6, en;q=0.4


*/

API

function parse(rawMessage: string, opts: HttpZParserOptions = {}): HttpZParserModel | never

Parses HTTP request/response raw message and returns a model.

  • rawMessage: string - HTTP raw message.
  • opts: HttpZParserOptions - options, optional.
const messageModel = parse(plainMessage)

function build(messageModel: HttpZBuilderModel, opts?: HttpZBuilderOptions): string | never

Builds HTTP request/response raw message from the model.

  • messageModel: HttpZBuilderModel - HTTP message model.
  • opts: HttpZBuilderOptions - options, optional.
const plainMessageParsed = build(messageModel)

utils: object

Different utils used by the library. Can be used externally.

consts: object

Different HTTP constants (methods, headers, etc.)

References

License

Licensed under the MIT license.

Author

Alexander Mac

Keywords

http

FAQs

Package last updated on 06 May 2025

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