diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-03-18 22:43:01 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-03-18 22:43:01 +0900 |
| commit | c1c3f2d77a1107fad8fb54ddc90c4c4c5b3af75f (patch) | |
| tree | 9663de41acff36c2e137f907e70c14515cd9be96 /src/HttpServerBodyCommand.cc | |
| parent | e0b42f2795ab37b21321e7b790578bef27dba109 (diff) | |
Return text/javascript as Content-Type if jsoncallback is given.
Diffstat (limited to 'src/HttpServerBodyCommand.cc')
| -rw-r--r-- | src/HttpServerBodyCommand.cc | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/HttpServerBodyCommand.cc b/src/HttpServerBodyCommand.cc index a41248d2..de5d1684 100644 --- a/src/HttpServerBodyCommand.cc +++ b/src/HttpServerBodyCommand.cc @@ -101,6 +101,13 @@ createJsonRpcErrorResponse } } // namespace +namespace { +std::string getJsonRpcContentType(bool script) +{ + return script ? "text/javascript" : "application/json-rpc"; +} +} // namespace + void HttpServerBodyCommand::sendJsonRpcResponse (const rpc::RpcResponse& res, const std::string& callback) @@ -108,7 +115,8 @@ void HttpServerBodyCommand::sendJsonRpcResponse bool gzip = httpServer_->supportsGZip(); std::string responseData = res.toJson(callback, gzip); if(res.code == 0) { - httpServer_->feedResponse(responseData, "application/json-rpc"); + httpServer_->feedResponse(responseData, + getJsonRpcContentType(!callback.empty())); } else { httpServer_->disableKeepAlive(); std::string httpCode; @@ -123,7 +131,8 @@ void HttpServerBodyCommand::sendJsonRpcResponse httpCode = "500 Internal Server Error"; }; httpServer_->feedResponse(httpCode, A2STR::NIL, - responseData, "application/json-rpc"); + responseData, + getJsonRpcContentType(!callback.empty())); } addHttpServerResponseCommand(); } @@ -134,7 +143,8 @@ void HttpServerBodyCommand::sendJsonRpcBatchResponse { bool gzip = httpServer_->supportsGZip(); std::string responseData = rpc::toJsonBatch(results, callback, gzip); - httpServer_->feedResponse(responseData, "application/json-rpc"); + httpServer_->feedResponse(responseData, + getJsonRpcContentType(!callback.empty())); addHttpServerResponseCommand(); } |
