comparison OrthancStone/Sources/Loaders/DicomSource.cpp @ 1845:ca85b6d60bca

removed duplicate slash in DICOMweb sources
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 24 Jun 2021 16:46:22 +0200
parents 28755e42c007
children 3889ae96d2e9
comparison
equal deleted inserted replaced
1844:58049bdebdc3 1845:ca85b6d60bca
30 30
31 #include <boost/algorithm/string/predicate.hpp> 31 #include <boost/algorithm/string/predicate.hpp>
32 32
33 namespace OrthancStone 33 namespace OrthancStone
34 { 34 {
35 static std::string EncodeGetArguments(const std::string& uri, 35 static std::string EncodeGetArguments(const std::map<std::string, std::string>& arguments)
36 const std::map<std::string, std::string>& arguments) 36 {
37 { 37 std::string s;
38 std::string s = uri;
39 bool first = true; 38 bool first = true;
40 39
41 for (std::map<std::string, std::string>::const_iterator 40 for (std::map<std::string, std::string>::const_iterator
42 it = arguments.begin(); it != arguments.end(); ++it) 41 it = arguments.begin(); it != arguments.end(); ++it)
43 { 42 {
55 } 54 }
56 55
57 // TODO: Call Orthanc::Toolbox::UriEncode() ? 56 // TODO: Call Orthanc::Toolbox::UriEncode() ?
58 57
59 return s; 58 return s;
59 }
60
61
62 static std::string AddUriSuffix(const std::string& base,
63 const std::string& suffix)
64 {
65 if (base.empty())
66 {
67 return suffix;
68 }
69 else if (suffix.empty())
70 {
71 return base;
72 }
73 else
74 {
75 char lastBase = base[base.size() - 1];
76
77 if (lastBase == '/' &&
78 suffix[0] == '/')
79 {
80 return base + suffix.substr(1);
81 }
82 else if (lastBase == '/' ||
83 suffix[0] == '/')
84 {
85 return base + suffix;
86 }
87 else
88 {
89 return base + "/" + suffix;
90 }
91 }
60 } 92 }
61 93
62 94
63 void DicomSource::SetOrthancSource(const Orthanc::WebServiceParameters& parameters) 95 void DicomSource::SetOrthancSource(const Orthanc::WebServiceParameters& parameters)
64 { 96 {
194 case DicomSourceType_DicomWeb: 226 case DicomSourceType_DicomWeb:
195 { 227 {
196 std::unique_ptr<HttpCommand> command(new HttpCommand); 228 std::unique_ptr<HttpCommand> command(new HttpCommand);
197 229
198 command->SetMethod(Orthanc::HttpMethod_Get); 230 command->SetMethod(Orthanc::HttpMethod_Get);
199 command->SetUrl(webService_.GetUrl() + EncodeGetArguments(uri, arguments)); 231 command->SetUrl(AddUriSuffix(webService_.GetUrl(), uri + EncodeGetArguments(arguments)));
200 command->SetHttpHeaders(webService_.GetHttpHeaders()); 232 command->SetHttpHeaders(webService_.GetHttpHeaders());
201 233
202 for (std::map<std::string, std::string>::const_iterator 234 for (std::map<std::string, std::string>::const_iterator
203 it = headers.begin(); it != headers.end(); ++it) 235 it = headers.begin(); it != headers.end(); ++it)
204 { 236 {
239 body["Arguments"] = args; 271 body["Arguments"] = args;
240 body["HttpHeaders"] = h; 272 body["HttpHeaders"] = h;
241 273
242 std::unique_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand); 274 std::unique_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand);
243 command->SetMethod(Orthanc::HttpMethod_Post); 275 command->SetMethod(Orthanc::HttpMethod_Post);
244 command->SetUri(orthancDicomWebRoot_ + "/servers/" + serverName_ + "/get"); 276 command->SetUri(AddUriSuffix(orthancDicomWebRoot_, "/servers/" + serverName_ + "/get"));
245 command->SetBody(body); 277 command->SetBody(body);
246 278
247 if (protection.get()) 279 if (protection.get())
248 { 280 {
249 command->AcquirePayload(protection.release()); 281 command->AcquirePayload(protection.release());