Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tootallnate/node-http-stack
A `StreamStack` implementation of the HTTP protocol, for NodeJS.
https://github.com/tootallnate/node-http-stack
Last synced: 5 days ago
JSON representation
A `StreamStack` implementation of the HTTP protocol, for NodeJS.
- Host: GitHub
- URL: https://github.com/tootallnate/node-http-stack
- Owner: TooTallNate
- License: mit
- Created: 2010-11-04T06:40:25.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2011-04-15T18:42:52.000Z (over 13 years ago)
- Last Synced: 2024-12-10T14:06:30.633Z (17 days ago)
- Language: JavaScript
- Homepage:
- Size: 616 KB
- Stars: 9
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
node-http-stack
===============
### A [StreamStack][] implementation of the HTTP protocol for [Node][].This module exposes two concrete `StreamStack` implementations:
`HttpRequestStack` and `HttpResponseStack`. Together they can be used to write
and/or respond to HTTP requests.This is an alternative to the built-in core `http` module. It is designed
to be more lenient, as well as being written with the `StreamStack` ideology.HTTP Request
------------In this typical example, we'll establish a `net.Stream` connection to
_www.google.com_ on port 80 and send an HTTP request for `/`:var conn = require('net').createConnection(80, 'www.google.com');
conn.on("connect", function() {
var req = new HttpRequestStack(conn);
// 'response' gets emitted when the HTTP headers have been recieved
req.on("response", function(res) {
console.error(res.headers);
});
// The body of the response will be piped to 'stdout'
req.pipe(process.stdout);// Initiate a GET request for '/' with no request body
req.get("/", [
"Host: www.google.com"
]);
req.end();
});Instead, in this example, we'll `write()` a request to __stdout__. Don't
expect there to be any response, but it's useful to see what's being written:var request = new HttpRequestStack(process.stdout);
// Write an HTTP post request to stdout
var body = "hello!\n";
request.post("/", [
"Content-Length: " + body.length,
"Content-Type: text/plain",
"Host: example.com"
]);
request.end(body);
--> POST / HTTP/1.1
--> Content-Length: 7
--> Content-Type: text/plain
--> Host: example.com
-->
--> hello!HTTP Response
-------------You can use `HttpResponseStack`s to respond to HTTP requests from a `net.Server`:
require('net').createServer(function(stream) {
var res = new HttpResponseStack(stream);
// 'request' is emitted when HTTP headers from a request have been parsed
res.on("request", function(request) {
res.writeHead(200, [
'Content-Type: text/plain'
]);
res.end('Hello World\n');
});
}).listen(8124, 'localhost');TODO
----- Chunked encoding/decoding
- Keep-Alive (needs chunked encoding)
- Testing...[StreamStack]: http://github.com/TooTallNate/node-stream-stack
[Node]: http://nodejs.org