Mercurial > hg > orthanc
comparison Core/RestApi/RestApi.cpp @ 1446:8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 01 Jul 2015 13:16:12 +0200 |
parents | f3672356c121 |
children | f967bdf8534e |
comparison
equal
deleted
inserted
replaced
1445:d26c8a93d05a | 1446:8dc80ba768aa |
---|---|
49 RestApi& api_; | 49 RestApi& api_; |
50 RestApiOutput& output_; | 50 RestApiOutput& output_; |
51 HttpMethod method_; | 51 HttpMethod method_; |
52 const IHttpHandler::Arguments& headers_; | 52 const IHttpHandler::Arguments& headers_; |
53 const IHttpHandler::Arguments& getArguments_; | 53 const IHttpHandler::Arguments& getArguments_; |
54 const std::string& postData_; | 54 const char* bodyData_; |
55 size_t bodySize_; | |
55 | 56 |
56 public: | 57 public: |
57 HttpHandlerVisitor(RestApi& api, | 58 HttpHandlerVisitor(RestApi& api, |
58 RestApiOutput& output, | 59 RestApiOutput& output, |
59 HttpMethod method, | 60 HttpMethod method, |
60 const IHttpHandler::Arguments& headers, | 61 const IHttpHandler::Arguments& headers, |
61 const IHttpHandler::Arguments& getArguments, | 62 const IHttpHandler::Arguments& getArguments, |
62 const std::string& postData) : | 63 const char* bodyData, |
64 size_t bodySize) : | |
63 api_(api), | 65 api_(api), |
64 output_(output), | 66 output_(output), |
65 method_(method), | 67 method_(method), |
66 headers_(headers), | 68 headers_(headers), |
67 getArguments_(getArguments), | 69 getArguments_(getArguments), |
68 postData_(postData) | 70 bodyData_(bodyData), |
71 bodySize_(bodySize) | |
69 { | 72 { |
70 } | 73 } |
71 | 74 |
72 virtual bool Visit(const RestApiHierarchy::Resource& resource, | 75 virtual bool Visit(const RestApiHierarchy::Resource& resource, |
73 const UriComponents& uri, | 76 const UriComponents& uri, |
85 return true; | 88 return true; |
86 } | 89 } |
87 | 90 |
88 case HttpMethod_Post: | 91 case HttpMethod_Post: |
89 { | 92 { |
90 RestApiPostCall call(output_, api_, headers_, components, trailing, uri, postData_); | 93 RestApiPostCall call(output_, api_, headers_, components, trailing, uri, bodyData_, bodySize_); |
91 resource.Handle(call); | 94 resource.Handle(call); |
92 return true; | 95 return true; |
93 } | 96 } |
94 | 97 |
95 case HttpMethod_Delete: | 98 case HttpMethod_Delete: |
99 return true; | 102 return true; |
100 } | 103 } |
101 | 104 |
102 case HttpMethod_Put: | 105 case HttpMethod_Put: |
103 { | 106 { |
104 RestApiPutCall call(output_, api_, headers_, components, trailing, uri, postData_); | 107 RestApiPutCall call(output_, api_, headers_, components, trailing, uri, bodyData_, bodySize_); |
105 resource.Handle(call); | 108 resource.Handle(call); |
106 return true; | 109 return true; |
107 } | 110 } |
108 | 111 |
109 default: | 112 default: |
159 bool RestApi::Handle(HttpOutput& output, | 162 bool RestApi::Handle(HttpOutput& output, |
160 HttpMethod method, | 163 HttpMethod method, |
161 const UriComponents& uri, | 164 const UriComponents& uri, |
162 const Arguments& headers, | 165 const Arguments& headers, |
163 const GetArguments& getArguments, | 166 const GetArguments& getArguments, |
164 const std::string& postData) | 167 const char* bodyData, |
168 size_t bodySize) | |
165 { | 169 { |
166 RestApiOutput wrappedOutput(output, method); | 170 RestApiOutput wrappedOutput(output, method); |
167 | 171 |
168 #if ORTHANC_PUGIXML_ENABLED == 1 | 172 #if ORTHANC_PUGIXML_ENABLED == 1 |
169 // Look if the user wishes XML answers instead of JSON | 173 // Look if the user wishes XML answers instead of JSON |
189 #endif | 193 #endif |
190 | 194 |
191 Arguments compiled; | 195 Arguments compiled; |
192 HttpToolbox::CompileGetArguments(compiled, getArguments); | 196 HttpToolbox::CompileGetArguments(compiled, getArguments); |
193 | 197 |
194 HttpHandlerVisitor visitor(*this, wrappedOutput, method, headers, compiled, postData); | 198 HttpHandlerVisitor visitor(*this, wrappedOutput, method, headers, compiled, bodyData, bodySize); |
195 | 199 |
196 if (root_.LookupResource(uri, visitor)) | 200 if (root_.LookupResource(uri, visitor)) |
197 { | 201 { |
198 wrappedOutput.Finalize(); | 202 wrappedOutput.Finalize(); |
199 return true; | 203 return true; |