Skip to content

http.Parser would be great to have. #21202

Closed
@qubyte

Description

@qubyte

I've recently been doing some work in which I needed access to the individual requests and responses from a pair of streams (it's a proxy of sorts and I'm only working with HTTP/1.1). For requests, recent changes to http.Server have meant I can fool a server instance into parsing request objects from a stream. Responses have been more challenging...

As it stands I've had to make use of the http_parser binding and IncomingMessage.prototype._addHeaderLine, both of which are internals. In my quest to understand how to use the http_parser binding, I came across this comment:

// TODO: http.Parser should be a Writable emits request/response events.

This Parser would eliminate all the hacks and use of private API in my code!

Alas, the comment is rather old. It got me thinking about how it might be implemented though. My understanding is that Parser would have to be instantiated either for requests or responses since it would wrap an underlying HTTPParser instance. On that assumption, my questions are:

  • Does a response need knowledge of a request in some circumstances in order to be parsed (ruling out Parser in principle)?
  • Is this an intrinsically difficult task (the complexity in the HTTP related modules points to yes).
  • Would refactoring HTTP modules to use Parser lead to a nasty performance hit which my limited understanding has missed?
  • Would some effort to do such a refactor be welcomed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpIssues or PRs related to the http subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions