diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index 02065813..26645c2a 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -95,7 +95,7 @@ module.exports = function(){ // request.post({ url:sqlapi, body:qs, json:true, - headers:{hostname:sqlapihostname} + headers:{host: sqlapihostname} }, function(err, res, body) { if (err){ diff --git a/test/acceptance/server.js b/test/acceptance/server.js index db4b9498..ab10375c 100644 --- a/test/acceptance/server.js +++ b/test/acceptance/server.js @@ -1126,6 +1126,37 @@ suite('server', function() { ); }); + test("passes hostname header to sqlapi", function(done){ + var qo = { + sql: "SELECT * from gadm4", + map_key: 1234 + }; + var sqlapi; + Step( + function sendRequest(err) { + var next = this; + assert.response(server, { + headers: {host: 'localhost'}, + url: '/tiles/gadm4/6/31/24.png?' + querystring.stringify(qo), + method: 'GET' + },{}, function(res) { next(null, res); }); + }, + function checkResponse(err, res) { + if ( err ) throw err; + assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); + var last_request = sqlapi_server.getLastRequest(); + assert.ok(last_request); + var host = last_request.headers['host']; + assert.ok(host); + assert.equal(host, 'localhost.donot_look_this_up'); + return null; + }, + function finish(err) { + done(err); + } + ); + }); + test("requests to skip cache on sqlapi error", function(done){ var qo = { sql: "SELECT g.cartodb_id, g.codineprov, t.the_geom_webmercator " diff --git a/test/support/SQLAPIEmu.js b/test/support/SQLAPIEmu.js index 18add297..f2411a5f 100644 --- a/test/support/SQLAPIEmu.js +++ b/test/support/SQLAPIEmu.js @@ -6,10 +6,14 @@ var o = function(port, cb) { this.queries = []; var that = this; + this.requests = []; this.sqlapi_server = http.createServer(function(req,res) { //console.log("server got request with method " + req.method); var query; + + that.requests.push(req); + if ( req.method == 'GET' ) { query = url.parse(req.url, true).query; that.handleQuery(query, res); @@ -68,5 +72,9 @@ o.prototype.close = function(cb) { this.sqlapi_server.close(cb); }; +o.prototype.getLastRequest = function() { + return this.requests.pop(); +}; + module.exports = o;