aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--webserver/webservd/dbus_request_handler.cc4
-rw-r--r--webserver/webservd/dbus_request_handler.h2
-rw-r--r--webserver/webservd/request.cc12
-rw-r--r--webserver/webservd/request_handler_interface.h2
4 files changed, 16 insertions, 4 deletions
diff --git a/webserver/webservd/dbus_request_handler.cc b/webserver/webservd/dbus_request_handler.cc
index 277d651..f9362c2 100644
--- a/webserver/webservd/dbus_request_handler.cc
+++ b/webserver/webservd/dbus_request_handler.cc
@@ -50,10 +50,12 @@ DBusRequestHandler::DBusRequestHandler(Server* server,
handler_proxy_{handler_proxy} {
}
-void DBusRequestHandler::HandleRequest(Request* request) {
+void DBusRequestHandler::HandleRequest(Request* request,
+ const std::string& src) {
std::vector<std::tuple<std::string, std::string>> headers;
for (const auto& pair : request->GetHeaders())
headers.emplace_back(pair.first, pair.second);
+ headers.emplace_back("Source-Host", src);
std::vector<std::tuple<int32_t, std::string, std::string, std::string,
std::string>> files;
diff --git a/webserver/webservd/dbus_request_handler.h b/webserver/webservd/dbus_request_handler.h
index 3171f8a..f90e40b 100644
--- a/webserver/webservd/dbus_request_handler.h
+++ b/webserver/webservd/dbus_request_handler.h
@@ -36,7 +36,7 @@ class DBusRequestHandler final : public RequestHandlerInterface {
// Called to process an incoming HTTP request this handler is subscribed
// to handle.
- void HandleRequest(Request* request) override;
+ void HandleRequest(Request* request, const std::string& src) override;
private:
Server* server_{nullptr};
diff --git a/webserver/webservd/request.cc b/webserver/webservd/request.cc
index 27e0b69..bd04d26 100644
--- a/webserver/webservd/request.cc
+++ b/webserver/webservd/request.cc
@@ -14,7 +14,9 @@
#include "webservd/request.h"
+#include <arpa/inet.h>
#include <microhttpd.h>
+#include <netinet/in.h>
#include <base/bind.h>
#include <base/files/file.h>
@@ -251,8 +253,16 @@ void Request::ForwardRequestToHandler() {
protocol_handler_->AddRequest(this);
auto p = protocol_handler_->request_handlers_.find(request_handler_id_);
CHECK(p != protocol_handler_->request_handlers_.end());
+ const MHD_ConnectionInfo* info = MHD_get_connection_info(
+ connection_, MHD_CONNECTION_INFO_CLIENT_ADDRESS);
+ struct sockaddr_in6 *sock_addr;
+ char src[INET6_ADDRSTRLEN] = {};
+ if (info) {
+ sock_addr = reinterpret_cast<struct sockaddr_in6 *>(info->client_addr);
+ inet_ntop(AF_INET6,&sock_addr->sin6_addr, src, INET6_ADDRSTRLEN);
+ }
// Send the request over D-Bus and await the response.
- p->second.handler->HandleRequest(this);
+ p->second.handler->HandleRequest(this, src);
} else {
// There was no handler found when request was made, respond with
// 404 Page Not Found.
diff --git a/webserver/webservd/request_handler_interface.h b/webserver/webservd/request_handler_interface.h
index fb3a25c..fae5fa2 100644
--- a/webserver/webservd/request_handler_interface.h
+++ b/webserver/webservd/request_handler_interface.h
@@ -30,7 +30,7 @@ class RequestHandlerInterface {
RequestHandlerInterface() = default;
virtual ~RequestHandlerInterface() = default;
- virtual void HandleRequest(Request* request) = 0;
+ virtual void HandleRequest(Request* request, const std::string& src) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(RequestHandlerInterface);