diff options
author | Christian Franke <nobody@nowhere.ws> | 2014-02-18 02:43:27 +0100 |
---|---|---|
committer | Christian Franke <nobody@nowhere.ws> | 2014-02-18 02:43:27 +0100 |
commit | 23919093c31cdfc7673ba3df149e555ca5867406 (patch) | |
tree | b7acc812c640f42b5fc94a0a22b405163353905f | |
parent | ff8bc5575082e08d5b8232bb61740308a36afa6a (diff) |
Use http directly
-rw-r--r-- | server.js | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -2,7 +2,7 @@ var express = require('express'); var fs = require('fs'); -var request = require('request'); +var http = require('http'); var MjpegProxy = require('mjpeg-proxy').MjpegProxy; var app = express(); @@ -32,16 +32,22 @@ function SimpleProxy(url) { self.url = url; self.handle_request = function(req, res) { - request(self.url, function(err, response, body) { - if (err) { - console.log("Simple proxy " + self.url + " failed."); - console.log(err); + var proxy = http.request(self.url, function(proxy_res) { + proxy_res.on('data', function(chunk) { + res.write(chunk, 'binary'); + }); + proxy_res.on('end', function() { res.end(); - return; - } - res.write(body); + }); + res.writeHead(proxy_res.statusCode, + proxy_res.headers); + }); + proxy.on('error', function(err) { + console.log("Simple proxy " + self.url + " failed:"); + console.log(err); res.end(); }); + proxy.end(); }; } |