This repository was archived by the owner on Mar 25, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
This repository was archived by the owner on Mar 25, 2018. It is now read-only.
Making http "hookable" #6
Copy link
Copy link
Open
Labels
Description
@nodejs/http ... Pulled over to a new issue from #2 (comment)
One of the possible approaches we can take with the http module is allowing third party modules to systematically replace core functions of the http implementation with their own bits. To do this we would need to:
- Clearly identify which bits are replaceable
- Clearly define the API / contract that the replacement components would need to implement
- Clearly define the API for registering those replacements
- Refactor the current implementation to make reuse and replacement of key parts easier / possible
To keep things as simple as possible, I'd recommend that we identify the replaceable pieces as coarsely as possible. This is just a strawman at this point.... feel free to knock it down.
- Allow the entire HTTP Parser implementation to be replaced. This would entail wrapping the HTTP Parser into a JS API and providing an API for developers to replace the parser in use (e.g. something like:
const http = require('http'); http.useParser(myParser);) - Allow parsing handlers for individual HTTP headers to be registered. This would be part of the new HTTP Parser wrapper API mentioned above. The existing http-parser implementation would need to be modified to use the registered callbacks to parse specific header field values. Custom HTTP parser implementations would be expected to follow the same contract. (e.g. something like:
const http = require('http'); http.onHeader('x-foo', myFooParser);) - On the server side, allow the Request handling logic to be replaced. Once the request has been parsed, it's handed off to logic that determines the handling. Alternative implementations would be expected to support the existing API contract but could extend that behavior and provide alternative APIs:
const http = require('http');
const myimpl = require('my-implementation');
// myimpl is a complete reimplementation of the request handling logic, as opposed to
// just a callback...
const server = http.createServer(myimpl);
server.listen(8080);
Not quite sure yet what all would need to happen on the client side... still working through that. Thoughts?