Mercurial > hg > orthanc
comparison Core/HttpServer/HttpToolbox.cpp @ 1571:3232f1c995a5
provide the origin of the requests to HTTP handlers
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 25 Aug 2015 11:04:19 +0200 |
parents | 5ba7471780ae |
children | 94990da8710e |
comparison
equal
deleted
inserted
replaced
1570:2bd2c280f9b5 | 1571:3232f1c995a5 |
---|---|
39 | 39 |
40 #include "HttpOutput.h" | 40 #include "HttpOutput.h" |
41 #include "StringHttpOutput.h" | 41 #include "StringHttpOutput.h" |
42 | 42 |
43 | 43 |
44 static const char* LOCALHOST = "localhost"; | |
45 | |
46 | |
47 | |
44 namespace Orthanc | 48 namespace Orthanc |
45 { | 49 { |
46 static void SplitGETNameValue(IHttpHandler::GetArguments& result, | 50 static void SplitGETNameValue(IHttpHandler::GetArguments& result, |
47 const char* start, | 51 const char* start, |
48 const char* end) | 52 const char* end) |
194 } | 198 } |
195 | 199 |
196 | 200 |
197 bool HttpToolbox::SimpleGet(std::string& result, | 201 bool HttpToolbox::SimpleGet(std::string& result, |
198 IHttpHandler& handler, | 202 IHttpHandler& handler, |
203 RequestOrigin origin, | |
199 const std::string& uri) | 204 const std::string& uri) |
200 { | 205 { |
201 IHttpHandler::Arguments headers; // No HTTP header | 206 IHttpHandler::Arguments headers; // No HTTP header |
202 | 207 |
203 UriComponents curi; | 208 UriComponents curi; |
205 ParseGetQuery(curi, getArguments, uri.c_str()); | 210 ParseGetQuery(curi, getArguments, uri.c_str()); |
206 | 211 |
207 StringHttpOutput stream; | 212 StringHttpOutput stream; |
208 HttpOutput http(stream, false /* no keep alive */); | 213 HttpOutput http(stream, false /* no keep alive */); |
209 | 214 |
210 if (handler.Handle(http, HttpMethod_Get, curi, headers, getArguments, | 215 if (handler.Handle(http, origin, LOCALHOST, "", HttpMethod_Get, curi, |
211 NULL /* no body for GET */, 0)) | 216 headers, getArguments, NULL /* no body for GET */, 0)) |
212 { | 217 { |
213 stream.GetOutput(result); | 218 stream.GetOutput(result); |
214 return true; | 219 return true; |
215 } | 220 } |
216 else | 221 else |
220 } | 225 } |
221 | 226 |
222 | 227 |
223 static bool SimplePostOrPut(std::string& result, | 228 static bool SimplePostOrPut(std::string& result, |
224 IHttpHandler& handler, | 229 IHttpHandler& handler, |
230 RequestOrigin origin, | |
225 HttpMethod method, | 231 HttpMethod method, |
226 const std::string& uri, | 232 const std::string& uri, |
227 const char* bodyData, | 233 const char* bodyData, |
228 size_t bodySize) | 234 size_t bodySize) |
229 { | 235 { |
234 Toolbox::SplitUriComponents(curi, uri); | 240 Toolbox::SplitUriComponents(curi, uri); |
235 | 241 |
236 StringHttpOutput stream; | 242 StringHttpOutput stream; |
237 HttpOutput http(stream, false /* no keep alive */); | 243 HttpOutput http(stream, false /* no keep alive */); |
238 | 244 |
239 if (handler.Handle(http, method, curi, headers, getArguments, bodyData, bodySize)) | 245 if (handler.Handle(http, origin, LOCALHOST, "", method, curi, |
246 headers, getArguments, bodyData, bodySize)) | |
240 { | 247 { |
241 stream.GetOutput(result); | 248 stream.GetOutput(result); |
242 return true; | 249 return true; |
243 } | 250 } |
244 else | 251 else |
248 } | 255 } |
249 | 256 |
250 | 257 |
251 bool HttpToolbox::SimplePost(std::string& result, | 258 bool HttpToolbox::SimplePost(std::string& result, |
252 IHttpHandler& handler, | 259 IHttpHandler& handler, |
260 RequestOrigin origin, | |
253 const std::string& uri, | 261 const std::string& uri, |
254 const char* bodyData, | 262 const char* bodyData, |
255 size_t bodySize) | 263 size_t bodySize) |
256 { | 264 { |
257 return SimplePostOrPut(result, handler, HttpMethod_Post, uri, bodyData, bodySize); | 265 return SimplePostOrPut(result, handler, origin, HttpMethod_Post, uri, bodyData, bodySize); |
258 } | 266 } |
259 | 267 |
260 | 268 |
261 bool HttpToolbox::SimplePut(std::string& result, | 269 bool HttpToolbox::SimplePut(std::string& result, |
262 IHttpHandler& handler, | 270 IHttpHandler& handler, |
271 RequestOrigin origin, | |
263 const std::string& uri, | 272 const std::string& uri, |
264 const char* bodyData, | 273 const char* bodyData, |
265 size_t bodySize) | 274 size_t bodySize) |
266 { | 275 { |
267 return SimplePostOrPut(result, handler, HttpMethod_Put, uri, bodyData, bodySize); | 276 return SimplePostOrPut(result, handler, origin, HttpMethod_Put, uri, bodyData, bodySize); |
268 } | 277 } |
269 | 278 |
270 | 279 |
271 bool HttpToolbox::SimpleDelete(IHttpHandler& handler, | 280 bool HttpToolbox::SimpleDelete(IHttpHandler& handler, |
281 RequestOrigin origin, | |
272 const std::string& uri) | 282 const std::string& uri) |
273 { | 283 { |
274 UriComponents curi; | 284 UriComponents curi; |
275 Toolbox::SplitUriComponents(curi, uri); | 285 Toolbox::SplitUriComponents(curi, uri); |
276 | 286 |
278 IHttpHandler::GetArguments getArguments; // No GET argument for DELETE | 288 IHttpHandler::GetArguments getArguments; // No GET argument for DELETE |
279 | 289 |
280 StringHttpOutput stream; | 290 StringHttpOutput stream; |
281 HttpOutput http(stream, false /* no keep alive */); | 291 HttpOutput http(stream, false /* no keep alive */); |
282 | 292 |
283 return handler.Handle(http, HttpMethod_Delete, curi, headers, getArguments, | 293 return handler.Handle(http, origin, LOCALHOST, "", HttpMethod_Delete, curi, |
284 NULL /* no body for DELETE */, 0); | 294 headers, getArguments, NULL /* no body for DELETE */, 0); |
285 } | 295 } |
286 } | 296 } |