# HG changeset patch # User Sebastien Jodogne # Date 1515686243 -3600 # Node ID 28d017f770a30639088aace2cecc21d1cc4206cc # Parent 73cb8ada6078a49ae0e884e988623d41e63c313e Defaults to JSON answers, replace application/json by application/dicom+json diff -r 73cb8ada6078 -r 28d017f770a3 NEWS --- a/NEWS Fri Jan 05 09:54:31 2018 +0100 +++ b/NEWS Thu Jan 11 16:57:23 2018 +0100 @@ -1,6 +1,8 @@ Pending changes in the mainline =============================== +* Defaults to JSON answers instead of XML +* Use of "application/dicom+json" MIME type instead of "application/json" * Added "?expand" argument to "/servers" route * Fix generation of numeric tags part of sequences for ".../metadata" routes * Support for OpenBSD diff -r 73cb8ada6078 -r 28d017f770a3 Plugin/Dicom.cpp --- a/Plugin/Dicom.cpp Fri Jan 05 09:54:31 2018 +0100 +++ b/Plugin/Dicom.cpp Thu Jan 11 16:57:23 2018 +0100 @@ -701,7 +701,7 @@ std::string answer; GenerateSingleDicomAnswer(answer, wadoBase, dictionary, dicom, isXml, isBulkAccessible); OrthancPluginAnswerBuffer(context, output, answer.c_str(), answer.size(), - isXml ? "application/dicom+xml" : "application/json"); + isXml ? "application/dicom+xml" : "application/dicom+json"); } diff -r 73cb8ada6078 -r 28d017f770a3 Plugin/DicomResults.cpp --- a/Plugin/DicomResults.cpp Fri Jan 05 09:54:31 2018 +0100 +++ b/Plugin/DicomResults.cpp Thu Jan 11 16:57:23 2018 +0100 @@ -419,7 +419,7 @@ std::string answer; jsonWriter_.Flatten(answer); - OrthancPluginAnswerBuffer(context_, output_, answer.c_str(), answer.size(), "application/json"); + OrthancPluginAnswerBuffer(context_, output_, answer.c_str(), answer.size(), "application/dicom+json"); } } } diff -r 73cb8ada6078 -r 28d017f770a3 Plugin/DicomWebClient.cpp --- a/Plugin/DicomWebClient.cpp Fri Jan 05 09:54:31 2018 +0100 +++ b/Plugin/DicomWebClient.cpp Thu Jan 11 16:57:23 2018 +0100 @@ -285,7 +285,7 @@ std::map queryArguments; std::map httpHeaders; - httpHeaders["Accept"] = "application/json"; + httpHeaders["Accept"] = "application/dicom+json"; httpHeaders["Expect"] = ""; httpHeaders["Content-Type"] = mime; diff -r 73cb8ada6078 -r 28d017f770a3 Plugin/StowRs.cpp --- a/Plugin/StowRs.cpp Fri Jan 05 09:54:31 2018 +0100 +++ b/Plugin/StowRs.cpp Thu Jan 11 16:57:23 2018 +0100 @@ -61,24 +61,28 @@ if (!OrthancPlugins::LookupHttpHeader(accept, request, "accept")) { - return true; // By default, return XML Native DICOM Model + return false; // By default, return DICOM+JSON } Orthanc::Toolbox::ToLowerCase(accept); - if (accept == "application/json") + if (accept == "application/dicom+json" || + accept == "application/json" || + accept == "*/*") { return false; } - - if (accept != "application/dicom+xml" && - accept != "application/xml" && - accept != "text/xml" && - accept != "*/*") + else if (accept == "application/dicom+xml" || + accept == "application/xml" || + accept == "text/xml") { - OrthancPlugins::Configuration::LogError("Unsupported return MIME type: " + accept + ", will return XML"); + return true; } - - return true; + else + { + OrthancPlugins::Configuration::LogError("Unsupported return MIME type: " + accept + + ", will return DICOM+JSON"); + return false; + } } diff -r 73cb8ada6078 -r 28d017f770a3 Plugin/WadoRs.cpp --- a/Plugin/WadoRs.cpp Fri Jan 05 09:54:31 2018 +0100 +++ b/Plugin/WadoRs.cpp Thu Jan 11 16:57:23 2018 +0100 @@ -75,13 +75,11 @@ static bool AcceptMetadata(const OrthancPluginHttpRequest* request, bool& isXml) { - isXml = true; + isXml = false; // By default, return application/dicom+json std::string accept; - if (!OrthancPlugins::LookupHttpHeader(accept, request, "accept")) { - // By default, return "multipart/related; type=application/dicom+xml;" return true; } @@ -89,14 +87,14 @@ std::map attributes; OrthancPlugins::ParseContentType(application, attributes, accept); - if (application == "application/json") + if (application == "application/json" || + application == "application/dicom+json" || + application == "*/*") { - isXml = false; return true; } - if (application != "multipart/related" && - application != "*/*") + if (application != "multipart/related") { OrthancPlugins::Configuration::LogError("This WADO-RS plugin cannot generate the following content type: " + accept); return false; @@ -106,13 +104,22 @@ { std::string s = attributes["type"]; Orthanc::Toolbox::ToLowerCase(s); - if (s != "application/dicom+xml") + if (s == "application/dicom+xml") { - OrthancPlugins::Configuration::LogError("This WADO-RS plugin only supports application/json or " - "application/dicom+xml return types for metadata (" + accept + ")"); + isXml = true; + } + else + { + OrthancPlugins::Configuration::LogError("This WADO-RS plugin only supports application/dicom+xml " + "type for multipart/related accept (" + accept + ")"); return false; } } + else + { + OrthancPlugins::Configuration::LogError("Missing \"type\" in multipart/related accept type (" + accept + ")"); + return false; + } if (attributes.find("transfer-syntax") != attributes.end()) {