Hello everybody,
I tried to use Nodejs as a proxy to Apache so it can serve everything
that is static while dynamic content is generated by node. The main
request handler decides which one should process the request based on
url patterns.
The problem is that, when using Firefox, apache sends back gzipped
content. I thought it wouldn't matter so I just made Node send every
chunk to the client. But Firefox says that there is an encoding error
and can't display the page.
Chromium and lynx are fine since they don't even send the Accept-
Encoding header (well, Chromium does but for some reason, Apache
doesn't encode the response).
Is there something I'm missing ?
here is a sample of my code:
var apache = http.createClient(80, 'localhost');
function passToApache(req, res) {
sys.puts('transfering to Apache: '+req.method+' '+req.url);
var request = apache.request(req.method, req.url, req.headers);
req.addListener('end', function() {
request.end();
});
req.addListener('data', function(chunk) {
request.write(chunk);
});
request.addListener('response', function(response) {
sys.puts('received response');
sys.puts(''+response.statusCode+'
'+JSON.stringify(response.headers));
res.writeHead(response.statusCode, response.headers);
response.setEncoding('binary');
response.addListener('data', function(chunk) {
sys.puts('received data: '+chunk);
res.write(chunk);
});
response.addListener('end', function() {
sys.puts('end of request');
res.end();
});
});
}
var MainServer;
MainServer = http.createServer(function(request, response) {
sys.puts('received '+request.method+' '+request.url
+"\n"+JSON.stringify(request.headers));
if(/^\/node/.test(request.url)) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end("Hi, it's node =)\n");
}
else {
passToApache(request, response);
}
});
--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to
nod...@googlegroups.com.
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en.