diff 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
line wrap: on
line diff
--- a/Core/RestApi/RestApi.cpp	Sun Aug 23 11:13:03 2015 +0200
+++ b/Core/RestApi/RestApi.cpp	Tue Aug 25 11:04:19 2015 +0200
@@ -48,6 +48,9 @@
     private:
       RestApi& api_;
       RestApiOutput& output_;
+      RequestOrigin origin_;
+      const char* remoteIp_;
+      const char* username_;
       HttpMethod method_;
       const IHttpHandler::Arguments& headers_;
       const IHttpHandler::Arguments& getArguments_;
@@ -57,6 +60,9 @@
     public:
       HttpHandlerVisitor(RestApi& api,
                          RestApiOutput& output,
+                         RequestOrigin origin,
+                         const char* remoteIp,
+                         const char* username,
                          HttpMethod method,
                          const IHttpHandler::Arguments& headers,
                          const IHttpHandler::Arguments& getArguments,
@@ -64,6 +70,9 @@
                          size_t bodySize) :
         api_(api),
         output_(output),
+        origin_(origin),
+        remoteIp_(remoteIp),
+        username_(username),
         method_(method),
         headers_(headers),
         getArguments_(getArguments),
@@ -83,28 +92,32 @@
           {
             case HttpMethod_Get:
             {
-              RestApiGetCall call(output_, api_, headers_, components, trailing, uri, getArguments_);
+              RestApiGetCall call(output_, api_, origin_, remoteIp_, username_, 
+                                  headers_, components, trailing, uri, getArguments_);
               resource.Handle(call);
               return true;
             }
 
             case HttpMethod_Post:
             {
-              RestApiPostCall call(output_, api_, headers_, components, trailing, uri, bodyData_, bodySize_);
+              RestApiPostCall call(output_, api_, origin_, remoteIp_, username_, 
+                                   headers_, components, trailing, uri, bodyData_, bodySize_);
               resource.Handle(call);
               return true;
             }
 
             case HttpMethod_Delete:
             {
-              RestApiDeleteCall call(output_, api_, headers_, components, trailing, uri);
+              RestApiDeleteCall call(output_, api_, origin_, remoteIp_, username_, 
+                                     headers_, components, trailing, uri);
               resource.Handle(call);
               return true;
             }
 
             case HttpMethod_Put:
             {
-              RestApiPutCall call(output_, api_, headers_, components, trailing, uri, bodyData_, bodySize_);
+              RestApiPutCall call(output_, api_, origin_, remoteIp_, username_, 
+                                  headers_, components, trailing, uri, bodyData_, bodySize_);
               resource.Handle(call);
               return true;
             }
@@ -160,6 +173,9 @@
 
 
   bool RestApi::Handle(HttpOutput& output,
+                       RequestOrigin origin,
+                       const char* remoteIp,
+                       const char* username,
                        HttpMethod method,
                        const UriComponents& uri,
                        const Arguments& headers,
@@ -197,7 +213,8 @@
     Arguments compiled;
     HttpToolbox::CompileGetArguments(compiled, getArguments);
 
-    HttpHandlerVisitor visitor(*this, wrappedOutput, method, headers, compiled, bodyData, bodySize);
+    HttpHandlerVisitor visitor(*this, wrappedOutput, origin, remoteIp, username, 
+                               method, headers, compiled, bodyData, bodySize);
 
     if (root_.LookupResource(uri, visitor))
     {