Skip to content

Instantly share code, notes, and snippets.

@cyrusdavid
Created December 22, 2014 03:30
Show Gist options
  • Save cyrusdavid/5d5b2dfe144988e9fb08 to your computer and use it in GitHub Desktop.
Save cyrusdavid/5d5b2dfe144988e9fb08 to your computer and use it in GitHub Desktop.
var Thin = require('./lib/thin.js');
var winston = require('winston');
var log = new (winston.Logger)({
transports: [ new winston.transports.Console() ]
});
var es = require('event-stream');
var proxy = new Thin();
proxy.use(function(req, res, next) {
console.log(req.headers);
req.pipe(es.map(function(data, callback) {
console.log(data);
callback(null, data);
}));
next();
});
proxy.listen(8080, 'localhost', function(err) {
// .. error handling code ..
});
$ curl --proxy 'http://localhost:8080' httpbin.org/post -F 'hi=there' 52 ↵
{
"args": {},
"data": "",
"files": {},
"form": {},
"headers": {
"Connect-Time": "1",
"Connection": "close",
"Host": "httpbin.org",
"Total-Route-Time": "0",
"Transfer-Encoding": "chunked",
"Via": "1.1 vegur",
"X-Request-Id": "0e16080e-c1c6-47dd-8af0-d7da8633fd33"
},
"json": null,
"origin": "xx.xxx.xxx.xx",
"url": "http://httpbin.org/post"
}
$ curl httpbin.org/post -F 'hi=there'
{
"args": {},
"data": "",
"files": {},
"form": {
"hi": "there"
},
"headers": {
"Accept": "*/*",
"Connect-Time": "1",
"Connection": "close",
"Content-Length": "142",
"Content-Type": "multipart/form-data; boundary=------------------------830400dff393ba3b",
"Host": "httpbin.org",
"Total-Route-Time": "0",
"User-Agent": "curl/7.39.0",
"Via": "1.1 vegur",
"X-Request-Id": "e5d4d482-2bfc-4c04-a34d-2c1b3f37eaac"
},
"json": null,
"origin": "xx.xxx.xxx.xx",
"url": "http://httpbin.org/post"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment