Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,31 @@ var sendResponse = function(jDoc, myRes, ip, bid, callback, gzip) {

var responseHeaders = {'Content-Type': responseType, 'vary': 'Accept-Encoding', 'max-age': jDoc.secleft, 'cache-control': 'public, max-age='+jDoc.secleft+', no-transform', "Expires": jDoc.expires, "Last-Modified": jDoc.lastModified};

doc = JSON.stringify(jDoc);
var ext = bid.match(/\.[\w]+$/);
if (ext && (ext = ext[0])) {
// When the bid has an extension, we only return the first api.
var first = _.find(jDoc, function(api, key) {
return api && api.cname;
});
doc = first.result;

switch (ext) {
case ".kml":
case ".xml":
// When expecting response is KML or XML, we set the correct Content-Type
// and wrap it with quotes if it's a JSONP request.
responseHeaders['Content-Type'] = 'text/xml';
callback && (doc = "'"+ doc+"'");
break;
case ".json":
// Content-Type for JSON is already set above.
doc = JSON.stringify(doc);
default:
break;
}
} else {
doc = JSON.stringify(jDoc);
}

if (callback) {
doc = callback + '(' + doc + ');';
Expand Down