summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2014-02-18 02:43:27 +0100
committerChristian Franke <nobody@nowhere.ws>2014-02-18 02:43:27 +0100
commit23919093c31cdfc7673ba3df149e555ca5867406 (patch)
treeb7acc812c640f42b5fc94a0a22b405163353905f
parentff8bc5575082e08d5b8232bb61740308a36afa6a (diff)
Use http directly
-rw-r--r--server.js22
1 files changed, 14 insertions, 8 deletions
diff --git a/server.js b/server.js
index c9aea0b..40761b1 100644
--- a/server.js
+++ b/server.js
@@ -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();
};
}