Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merged v0.1.2/B and changed proxy controller to more accurately emula…
…te a proxy
- Loading branch information
Adithya C
committed
Mar 11, 2013
1 parent
6803f34
commit cd8b8b4
Showing
4 changed files
with
167 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
var common = require('./common'); | ||
var url = require('url'); | ||
var http = require('http'); | ||
var config = require('../system/config'); | ||
|
||
function forwardRequest(request,response) | ||
{ | ||
//For returning response to browser | ||
var final_response = ''; | ||
|
||
this.requestComplete = function(res) | ||
{ | ||
console.log('STATUS: ' + res.statusCode); | ||
console.log('HEADERS: ' + JSON.stringify(res.headers)); | ||
//res.setEncoding('utf8'); | ||
|
||
final_response.writeHead(res.statusCode,res.headers); | ||
|
||
res.on('data', function (chunk) { | ||
console.log('BODY: ' + chunk); | ||
final_response.write(chunk); | ||
}); | ||
|
||
res.on('end',function() { | ||
|
||
final_response.addTrailers(res.headers); | ||
final_response.end(); | ||
}); | ||
}; | ||
|
||
this.getURL = function(request,response) | ||
{ | ||
final_response = response; | ||
|
||
var | ||
query = url.parse(request.url).query.replace(/query=/,''), | ||
domain = query.split('/')[0], | ||
pathstring = '/'+query.slice(domain.length+1); | ||
|
||
console.log(domain+pathstring); | ||
|
||
var domainPort = config.getConfig().domainPort; | ||
|
||
var options = { | ||
host: domain, | ||
port: domainPort, | ||
path: pathstring | ||
}; | ||
|
||
http.get(options, this.requestComplete) | ||
.on('error', function(e) { | ||
console.log('problem with request: ' + e.message); | ||
final_response.writeHead(500,{'Content-Type': 'text/plain'}); | ||
final_response.write('Invalid URL Specified'); | ||
final_response.end(); | ||
}); | ||
|
||
}; | ||
|
||
this.postURL = function(request,response) | ||
{ | ||
|
||
}; | ||
|
||
//actual calling part | ||
var pathname = url.parse(request.url).pathname; | ||
console.log(pathname); | ||
console.log(this); | ||
var word = pathname.split('/')[2]; | ||
|
||
if(typeof(this[word]) === 'function') | ||
{ | ||
this[word](request,response); | ||
} | ||
else | ||
{ | ||
//common.errorEcho(request,response); | ||
|
||
final_response = response; | ||
|
||
var domain = config.getConfig().domain; | ||
var domainPort = config.getConfig().domainPort; | ||
var pathstring = request.url; | ||
|
||
console.log(domain+pathstring); | ||
|
||
var options = { | ||
host: domain, | ||
port: domainPort, | ||
path: pathstring | ||
}; | ||
|
||
http.get(options, this.requestComplete) | ||
.on('error', function(e) { | ||
console.log('problem with request: ' + e.message); | ||
final_response.writeHead(500,{'Content-Type': 'text/plain'}); | ||
final_response.write('Invalid URL Specified'); | ||
final_response.end(); | ||
}); | ||
|
||
} | ||
} | ||
|
||
exports.forwardRequest = forwardRequest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
port 8000 | ||
address 0.0.0.0 | ||
domain www.veooz.com | ||
domain localhost | ||
domainPort 9000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters