Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handle remote urls properly.

This includes respecting port, and watching for errors
from response and request.
  • Loading branch information...
commit 320a990922171089c643aa30cb7c1ba32a6f958e 1 parent 12bd555
Nikhil Marathe authored
Showing with 11 additions and 2 deletions.
  1. +11 −2 server.js
13 server.js
View
@@ -79,12 +79,19 @@ function handleUrl(request, response) {
var size = 0;
var error = false;
var parts = url.parse(remote);
- var client = http.createClient(80, parts.host);
+ var client = http.createClient(parseInt(parts.port)||80, parts.hostname);
+ client.on('error', function() {
+ getOut(500, response);
+ });
client.request('GET', parts.pathname || '/', {
- 'host' : parts.host
+ 'host' : parts.hostname
, 'user-agent' : 'Mugshot FaceDetector'
})
.on('response', function(remoteresponse) {
+ if( remoteresponse.statusCode != 200 ) {
+ getOut(500, "Remote server failed with status code " + remoteresponse.statusCode, response);
+ return;
+ }
remoteresponse.on('data', function(data) {
if( size > MAX_SIZE ) {
error = true;
@@ -120,6 +127,8 @@ function handleUrl(request, response) {
else
getOut(500, response);
});;
+ }).on('error', function() {
+ getOut(500, response);
}).end();
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.