Multiple MIME type Accept Headers for Wado-RS not supported

Hello Team,

The way in which the dicomweb plugin processes requests is a little at odds with the RFC2616 section 14. I first noticed it with WadoRs metadata requests, but it’s also an issue with Stow requests as was noted here: (https://groups.google.com/forum/#!searchin/orthanc-users/RFC2616/orthanc-users/9o5kItsMQI0/Og6B27YyBgAJ)

I’ve come up with a piecemeal approach to address this issue for the WadoRs metadata requests as a more comprehensive solution would require additional effort to the plugin code.

Currently this call below fails with the plugin reporting that “application/json, application/dicom+json” is not supported because the entire accept header fragment is being treated as a single MIME type.

curl -H “Accept:application/json, application/dicom+json” http://192.168.109.1:8045/dicom-web/studies/1.2.826.0.1.3680043.8.498.45262650864619686570108269135890142044/metadata

but these calls work:

curl -H “Accept:application/dicom+json” http://192.168.109.1:8045/dicom-web/studies/1.2.826.0.1.3680043.8.498.45262650864619686570108269135890142044/metadata

curl -H “Accept:application/json” http://192.168.109.1:8045/dicom-web/studies/1.2.826.0.1.3680043.8.498.45262650864619686570108269135890142044/metadata

I post my fix here for others who may have run into this issue.

To WadoRs.cpp

Add below include directives:

#include <boost/algorithm/string/trim.hpp>

In function AcceptMetadata ( )

Replace lines 119 - 124 with :

std::vectorstd::string accept_tokens;

Orthanc::toolbox::TokenizeString(accept_tokens, application, ‘,’) ;

if(accept_tokens.size() == 0)

accept_tokens.push_back(application);

for (size_t i = accept_tokens.size()-1; I >= 0; i-- )

{

application = accept_tokens[i];

boost::algorithm::trim(application) ;

if (application == “application/json” ||

application == “application/dicom+json” ||

application == “/”)

{

return true;

}

}

Thank you to Sébastien and the rest of the Orthanc contributors,

Mark

reposting code because of formatting

`

std::vectorstd::string accept_tokens;
Orthanc::toolbox::TokenizeString(accept_tokens, application, ‘,’) ;

if(accept_tokens.size() == 0)
accept_tokens.push_back(application);

for (size_t i = accept_tokens.size()-1; i >= 0; i-- )
{
application = accept_tokens[i];
boost::algorithm::trim(application) ;

if (application == “application/json” ||
application == “application/dicom+json” ||
application == “/”)
{
return true;
}
}

`

Hello,

Thanks for the patch! I have posted a slightly adapted version in the mainline:
https://bitbucket.org/sjodogne/orthanc-dicomweb/commits/105598b74e1ab205caff0a0cec97d78524603ac4

Regards,
Sébastien-