Skip to content

Instantly share code, notes, and snippets.

@Poetro
Created November 8, 2010 22:13
Show Gist options
  • Save Poetro/668369 to your computer and use it in GitHub Desktop.
Save Poetro/668369 to your computer and use it in GitHub Desktop.
request pass through
var express = require('express'),
underscore = require('underscore')._,
httpRequest = require('request'),
app = express.createServer(express.logger());
// For favicon requests just redirect them.
app.get('/favicon.ico', function (request, response) {
// Set the appropriate content type
response.writeHead(200, {
'Content-Type': 'image/x-icon'
});
httpRequest({
'uri' : 'http://example.com/favicon.ico',
'responseBodyStream': response
}, function (error, httpResponse, body) {
var length = [];
if (!error) {
length =underscore.select(httpResponse.headers, function (item, index) {
return index.toLowerCase() === 'content-length';
});
if (length.length) {
// Hide connect's error throwing.
response.headers['Content-Length'] = length[0];
response.end();
}
}
});
});
app.listen();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment