nodejs / http-parser

http request/response parser for c
MIT License
6.32k stars 1.53k forks source link

How to determine the boundaries of HTTP header? #493

Closed wonter closed 4 years ago

wonter commented 4 years ago

Hi

I am writing an http proxy and parsing HTTP messages using http-parser

In most cases, proxy will add some additional headers such as ‎X-Forwarded-Host, Proxy-Authorization and so on

So i'd like to split HTTP message to 3 parts which is:

  1. original header
  2. additional headers
  3. body

But http-parser doesn't provide some API to help me determine the boundaries of HTTP header

Is there any way to do it?

bnoordhuis commented 4 years ago

http-parser is basically a state machine so if you keep track of when your callbacks are invoked, you can keep track of the state.

on_header_field, on_header_value and on_headers_complete in particular are the callbacks you'd care about.