Permalink
Browse files

Implemented URL fetch API

  • Loading branch information...
1 parent 1fd699a commit 5f4b17b853a95de4d244a94175ce70e4451327b9 @nikhilm committed Nov 15, 2010
Showing with 23 additions and 5 deletions.
  1. +23 −5 server.js
View
28 server.js
@@ -40,28 +40,46 @@ function tempFile(callback) {
function handleUrl(request, response) {
tempFile(function(stream) {
- var url = "";
+ var remote = "";
request.on('data', function(data) {
- url += data.toString();
+ remote += data.toString();
});
request.on('end', function() {
- var client = http.createClient(80, url);
+ var parts = url.parse(remote);
+ var client = http.createClient(80, parts.host);
+ client.request('GET', parts.pathname || '/', {
+ 'host' : parts.host
+ , 'user-agent' : 'FaceDetector'
+ })
+ .on('response', function(remoteresponse) {
+ remoteresponse.on('data', function(data) {
+ stream.write(data);
+ })
+ .on('end', function() {
+ stream.on('close', function() {
+ reply(face.faces(stream.path), response);
+ });
+ stream.end();
+ })
+ .on('error', function() {
+ getOut(500, response);
+ });;
+ }).end();
});
});
};
function handleFile(request, response) {
tempFile(function(stream) {
request.on('data', function(data) {
- console.log("Wrting");
stream.write(data);
});
request.on('error', console.log);
request.on('end', function() {
- stream.end();
stream.on('close', function() {
reply(face.faces(stream.path), response);
});
+ stream.end();
});
});
};

0 comments on commit 5f4b17b

Please sign in to comment.