HTTP String Parser

0.0.6 · abandoned · verified Tue Apr 21

http-string-parser is a lightweight, proof-of-concept library designed to parse raw HTTP request and response messages from strings within Node.js environments. The package is currently at version 0.0.6, with its last known update in 2014, indicating it is no longer actively maintained. Its core functionality offers methods like `parseRequest`, `parseResponse`, `parseRequestLine`, `parseStatusLine`, and `parseHeaders` to break down HTTP messages into structured JavaScript objects. A key differentiator is its explicit admission of being a 'naive' parser, not leveraging Node.js core's C bindings for HTTP parsing or more robust alternatives like `http-pegjs`, which were even suggested as future replacements in its own README. It serves as a basic utility for scenarios where a simple, non-production-grade parsing of well-formed HTTP strings is sufficient, but lacks the robustness and ongoing support expected for modern applications.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates parsing a raw HTTP request and response string into structured JavaScript objects using the `parseRequest` and `parseResponse` methods.

const parser = require('http-string-parser');

const httpRequestString = `GET /api/data?id=123 HTTP/1.1\r\nHost: example.com\r\nUser-Agent: NodeParser/1.0\r\nContent-Type: application/json\r\nContent-Length: 20\r\n\r\n{"message": "hello"}`;

const httpResponseString = `HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 22\r\n\r\n{"status": "success"}`;

try {
  console.log('Parsing HTTP Request:');
  const request = parser.parseRequest(httpRequestString);
  console.log(JSON.stringify(request, null, 2));

  console.log('\nParsing HTTP Response:');
  const response = parser.parseResponse(httpResponseString);
  console.log(JSON.stringify(response, null, 2));
} catch (error) {
  console.error('An error occurred during parsing:', error.message);
}

view raw JSON →