Skip to content

Instantly share code, notes, and snippets.

@igorw

igorw/foo.js Secret

Last active December 16, 2015 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorw/75aae212a11ab642f864 to your computer and use it in GitHub Desktop.
Save igorw/75aae212a11ab642f864 to your computer and use it in GitHub Desktop.
var http = require('http');
function handle(req, rep) {
req.pipe(process.stdout);
req.on('end', function () {
rep.end();
console.log('');
});
}
var server = http.createServer(handle);
server.on('checkContinue', function (req, rep) {
if (!req.headers['x-foo']) {
console.log('did not have foo');
rep.writeHead(400);
rep.end();
return;
}
rep.writeContinue();
handle(req, rep);
});
server.listen(8080);
~$ curl localhost:8080 -d{0..1023} -H 'X-Foo: value' -v
* About to connect() to localhost port 8080 (#0)
* Trying ::1...
* Connection refused
* Trying 127.0.0.1...
* connected
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST / HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:8080
> Accept: */*
> X-Foo: value
> Content-Length: 4009
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
< Date: Fri, 03 May 2013 02:06:47 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
<
* Connection #0 to host localhost left intact
* Closing connection #0
~$ curl localhost:8080 -d{0..1023} -v
* About to connect() to localhost port 8080 (#0)
* Trying ::1...
* Connection refused
* Trying 127.0.0.1...
* connected
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST / HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:8080
> Accept: */*
> Content-Length: 4009
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
>
< HTTP/1.1 400 Bad Request
< Date: Fri, 03 May 2013 02:07:41 GMT
< Connection: close
< Transfer-Encoding: chunked
<
* Closing connection #0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment