comparison OrthancFramework/Sources/RestApi/RestApi.cpp @ 4330:a01b1c9cbef4

moving generic type definitions from IHttpHandler to HttpToolbox
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 25 Nov 2020 14:39:10 +0100
parents bf7b9edf6b81
children 80fd140b12ba
comparison
equal deleted inserted replaced
4329:9dc0e42f868b 4330:a01b1c9cbef4
40 RestApiOutput& output_; 40 RestApiOutput& output_;
41 RequestOrigin origin_; 41 RequestOrigin origin_;
42 const char* remoteIp_; 42 const char* remoteIp_;
43 const char* username_; 43 const char* username_;
44 HttpMethod method_; 44 HttpMethod method_;
45 const IHttpHandler::Arguments& headers_; 45 const HttpToolbox::Arguments& headers_;
46 const IHttpHandler::Arguments& getArguments_; 46 const HttpToolbox::Arguments& getArguments_;
47 const void* bodyData_; 47 const void* bodyData_;
48 size_t bodySize_; 48 size_t bodySize_;
49 49
50 public: 50 public:
51 HttpHandlerVisitor(RestApi& api, 51 HttpHandlerVisitor(RestApi& api,
52 RestApiOutput& output, 52 RestApiOutput& output,
53 RequestOrigin origin, 53 RequestOrigin origin,
54 const char* remoteIp, 54 const char* remoteIp,
55 const char* username, 55 const char* username,
56 HttpMethod method, 56 HttpMethod method,
57 const IHttpHandler::Arguments& headers, 57 const HttpToolbox::Arguments& headers,
58 const IHttpHandler::Arguments& getArguments, 58 const HttpToolbox::Arguments& getArguments,
59 const void* bodyData, 59 const void* bodyData,
60 size_t bodySize) : 60 size_t bodySize) :
61 api_(api), 61 api_(api),
62 output_(output), 62 output_(output),
63 origin_(origin), 63 origin_(origin),
71 { 71 {
72 } 72 }
73 73
74 virtual bool Visit(const RestApiHierarchy::Resource& resource, 74 virtual bool Visit(const RestApiHierarchy::Resource& resource,
75 const UriComponents& uri, 75 const UriComponents& uri,
76 const IHttpHandler::Arguments& components, 76 const HttpToolbox::Arguments& components,
77 const UriComponents& trailing) 77 const UriComponents& trailing)
78 { 78 {
79 if (resource.HasHandler(method_)) 79 if (resource.HasHandler(method_))
80 { 80 {
81 switch (method_) 81 switch (method_)
166 RequestOrigin origin, 166 RequestOrigin origin,
167 const char* remoteIp, 167 const char* remoteIp,
168 const char* username, 168 const char* username,
169 HttpMethod method, 169 HttpMethod method,
170 const UriComponents& uri, 170 const UriComponents& uri,
171 const Arguments& headers, 171 const HttpToolbox::Arguments& headers,
172 const GetArguments& getArguments, 172 const HttpToolbox::GetArguments& getArguments,
173 const void* bodyData, 173 const void* bodyData,
174 size_t bodySize) 174 size_t bodySize)
175 { 175 {
176 RestApiOutput wrappedOutput(output, method); 176 RestApiOutput wrappedOutput(output, method);
177 177
178 #if ORTHANC_ENABLE_PUGIXML == 1 178 #if ORTHANC_ENABLE_PUGIXML == 1
179 { 179 {
180 // Look if the client wishes XML answers instead of JSON 180 // Look if the client wishes XML answers instead of JSON
181 // http://www.w3.org/Protocols/HTTP/HTRQ_Headers.html#z3 181 // http://www.w3.org/Protocols/HTTP/HTRQ_Headers.html#z3
182 Arguments::const_iterator it = headers.find("accept"); 182 HttpToolbox::Arguments::const_iterator it = headers.find("accept");
183 if (it != headers.end()) 183 if (it != headers.end())
184 { 184 {
185 std::vector<std::string> accepted; 185 std::vector<std::string> accepted;
186 Toolbox::TokenizeString(accepted, it->second, ';'); 186 Toolbox::TokenizeString(accepted, it->second, ';');
187 for (size_t i = 0; i < accepted.size(); i++) 187 for (size_t i = 0; i < accepted.size(); i++)
198 } 198 }
199 } 199 }
200 } 200 }
201 #endif 201 #endif
202 202
203 Arguments compiled; 203 HttpToolbox::Arguments compiled;
204 HttpToolbox::CompileGetArguments(compiled, getArguments); 204 HttpToolbox::CompileGetArguments(compiled, getArguments);
205 205
206 HttpHandlerVisitor visitor(*this, wrappedOutput, origin, remoteIp, username, 206 HttpHandlerVisitor visitor(*this, wrappedOutput, origin, remoteIp, username,
207 method, headers, compiled, bodyData, bodySize); 207 method, headers, compiled, bodyData, bodySize);
208 208