Mercurial > hg > orthanc
comparison Core/RestApi/RestApi.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 | 4f8c8ef114db |
children | b1291df2f780 |
comparison
equal
deleted
inserted
replaced
1570:2bd2c280f9b5 | 1571:3232f1c995a5 |
---|---|
46 class HttpHandlerVisitor : public RestApiHierarchy::IVisitor | 46 class HttpHandlerVisitor : public RestApiHierarchy::IVisitor |
47 { | 47 { |
48 private: | 48 private: |
49 RestApi& api_; | 49 RestApi& api_; |
50 RestApiOutput& output_; | 50 RestApiOutput& output_; |
51 RequestOrigin origin_; | |
52 const char* remoteIp_; | |
53 const char* username_; | |
51 HttpMethod method_; | 54 HttpMethod method_; |
52 const IHttpHandler::Arguments& headers_; | 55 const IHttpHandler::Arguments& headers_; |
53 const IHttpHandler::Arguments& getArguments_; | 56 const IHttpHandler::Arguments& getArguments_; |
54 const char* bodyData_; | 57 const char* bodyData_; |
55 size_t bodySize_; | 58 size_t bodySize_; |
56 | 59 |
57 public: | 60 public: |
58 HttpHandlerVisitor(RestApi& api, | 61 HttpHandlerVisitor(RestApi& api, |
59 RestApiOutput& output, | 62 RestApiOutput& output, |
63 RequestOrigin origin, | |
64 const char* remoteIp, | |
65 const char* username, | |
60 HttpMethod method, | 66 HttpMethod method, |
61 const IHttpHandler::Arguments& headers, | 67 const IHttpHandler::Arguments& headers, |
62 const IHttpHandler::Arguments& getArguments, | 68 const IHttpHandler::Arguments& getArguments, |
63 const char* bodyData, | 69 const char* bodyData, |
64 size_t bodySize) : | 70 size_t bodySize) : |
65 api_(api), | 71 api_(api), |
66 output_(output), | 72 output_(output), |
73 origin_(origin), | |
74 remoteIp_(remoteIp), | |
75 username_(username), | |
67 method_(method), | 76 method_(method), |
68 headers_(headers), | 77 headers_(headers), |
69 getArguments_(getArguments), | 78 getArguments_(getArguments), |
70 bodyData_(bodyData), | 79 bodyData_(bodyData), |
71 bodySize_(bodySize) | 80 bodySize_(bodySize) |
81 { | 90 { |
82 switch (method_) | 91 switch (method_) |
83 { | 92 { |
84 case HttpMethod_Get: | 93 case HttpMethod_Get: |
85 { | 94 { |
86 RestApiGetCall call(output_, api_, headers_, components, trailing, uri, getArguments_); | 95 RestApiGetCall call(output_, api_, origin_, remoteIp_, username_, |
96 headers_, components, trailing, uri, getArguments_); | |
87 resource.Handle(call); | 97 resource.Handle(call); |
88 return true; | 98 return true; |
89 } | 99 } |
90 | 100 |
91 case HttpMethod_Post: | 101 case HttpMethod_Post: |
92 { | 102 { |
93 RestApiPostCall call(output_, api_, headers_, components, trailing, uri, bodyData_, bodySize_); | 103 RestApiPostCall call(output_, api_, origin_, remoteIp_, username_, |
104 headers_, components, trailing, uri, bodyData_, bodySize_); | |
94 resource.Handle(call); | 105 resource.Handle(call); |
95 return true; | 106 return true; |
96 } | 107 } |
97 | 108 |
98 case HttpMethod_Delete: | 109 case HttpMethod_Delete: |
99 { | 110 { |
100 RestApiDeleteCall call(output_, api_, headers_, components, trailing, uri); | 111 RestApiDeleteCall call(output_, api_, origin_, remoteIp_, username_, |
112 headers_, components, trailing, uri); | |
101 resource.Handle(call); | 113 resource.Handle(call); |
102 return true; | 114 return true; |
103 } | 115 } |
104 | 116 |
105 case HttpMethod_Put: | 117 case HttpMethod_Put: |
106 { | 118 { |
107 RestApiPutCall call(output_, api_, headers_, components, trailing, uri, bodyData_, bodySize_); | 119 RestApiPutCall call(output_, api_, origin_, remoteIp_, username_, |
120 headers_, components, trailing, uri, bodyData_, bodySize_); | |
108 resource.Handle(call); | 121 resource.Handle(call); |
109 return true; | 122 return true; |
110 } | 123 } |
111 | 124 |
112 default: | 125 default: |
158 } | 171 } |
159 | 172 |
160 | 173 |
161 | 174 |
162 bool RestApi::Handle(HttpOutput& output, | 175 bool RestApi::Handle(HttpOutput& output, |
176 RequestOrigin origin, | |
177 const char* remoteIp, | |
178 const char* username, | |
163 HttpMethod method, | 179 HttpMethod method, |
164 const UriComponents& uri, | 180 const UriComponents& uri, |
165 const Arguments& headers, | 181 const Arguments& headers, |
166 const GetArguments& getArguments, | 182 const GetArguments& getArguments, |
167 const char* bodyData, | 183 const char* bodyData, |
195 #endif | 211 #endif |
196 | 212 |
197 Arguments compiled; | 213 Arguments compiled; |
198 HttpToolbox::CompileGetArguments(compiled, getArguments); | 214 HttpToolbox::CompileGetArguments(compiled, getArguments); |
199 | 215 |
200 HttpHandlerVisitor visitor(*this, wrappedOutput, method, headers, compiled, bodyData, bodySize); | 216 HttpHandlerVisitor visitor(*this, wrappedOutput, origin, remoteIp, username, |
217 method, headers, compiled, bodyData, bodySize); | |
201 | 218 |
202 if (root_.LookupResource(uri, visitor)) | 219 if (root_.LookupResource(uri, visitor)) |
203 { | 220 { |
204 wrappedOutput.Finalize(); | 221 wrappedOutput.Finalize(); |
205 return true; | 222 return true; |