Return text/javascript as Content-Type if jsoncallback is given.

pull/1/head
Tatsuhiro Tsujikawa 2011-03-18 22:43:01 +09:00
parent e0b42f2795
commit c1c3f2d77a
1 changed files with 13 additions and 3 deletions

View File

@ -101,6 +101,13 @@ createJsonRpcErrorResponse
} }
} // namespace } // namespace
namespace {
std::string getJsonRpcContentType(bool script)
{
return script ? "text/javascript" : "application/json-rpc";
}
} // namespace
void HttpServerBodyCommand::sendJsonRpcResponse void HttpServerBodyCommand::sendJsonRpcResponse
(const rpc::RpcResponse& res, (const rpc::RpcResponse& res,
const std::string& callback) const std::string& callback)
@ -108,7 +115,8 @@ void HttpServerBodyCommand::sendJsonRpcResponse
bool gzip = httpServer_->supportsGZip(); bool gzip = httpServer_->supportsGZip();
std::string responseData = res.toJson(callback, gzip); std::string responseData = res.toJson(callback, gzip);
if(res.code == 0) { if(res.code == 0) {
httpServer_->feedResponse(responseData, "application/json-rpc"); httpServer_->feedResponse(responseData,
getJsonRpcContentType(!callback.empty()));
} else { } else {
httpServer_->disableKeepAlive(); httpServer_->disableKeepAlive();
std::string httpCode; std::string httpCode;
@ -123,7 +131,8 @@ void HttpServerBodyCommand::sendJsonRpcResponse
httpCode = "500 Internal Server Error"; httpCode = "500 Internal Server Error";
}; };
httpServer_->feedResponse(httpCode, A2STR::NIL, httpServer_->feedResponse(httpCode, A2STR::NIL,
responseData, "application/json-rpc"); responseData,
getJsonRpcContentType(!callback.empty()));
} }
addHttpServerResponseCommand(); addHttpServerResponseCommand();
} }
@ -134,7 +143,8 @@ void HttpServerBodyCommand::sendJsonRpcBatchResponse
{ {
bool gzip = httpServer_->supportsGZip(); bool gzip = httpServer_->supportsGZip();
std::string responseData = rpc::toJsonBatch(results, callback, gzip); std::string responseData = rpc::toJsonBatch(results, callback, gzip);
httpServer_->feedResponse(responseData, "application/json-rpc"); httpServer_->feedResponse(responseData,
getJsonRpcContentType(!callback.empty()));
addHttpServerResponseCommand(); addHttpServerResponseCommand();
} }