Jelajahi Sumber

feat: HttpService::AddTrustProxy AddNoProxy

ithewei 2 tahun lalu
induk
melakukan
a8c5c734ba
4 mengubah file dengan 14 tambahan dan 2 penghapusan
  1. 0 1
      docs/PLAN.md
  2. 1 1
      docs/cn/Channel.md
  3. 8 0
      http/server/HttpService.cpp
  4. 5 0
      http/server/HttpService.h

+ 0 - 1
docs/PLAN.md

@@ -14,7 +14,6 @@
 - wintls: SChannel is so hard :) need help
 - Path router: optimized matching via trie?
 - FileCache use LRUCache
-- HTTP TrustProxies
 
 ## Plan
 

+ 1 - 1
docs/cn/Channel.md

@@ -129,7 +129,7 @@ class SocketChannel : public Channel {
     // 返回本地地址
     std::string localaddr();
 
-    // 返回对地址
+    // 返回对地址
     std::string peeraddr();
 };
 

+ 8 - 0
http/server/HttpService.cpp

@@ -171,6 +171,14 @@ std::string HttpService::GetProxyUrl(const char* path) {
     return url;
 }
 
+void HttpService::AddTrustProxy(const char* host) {
+    trustProxies.emplace_back(host);
+}
+
+void HttpService::AddNoProxy(const char* host) {
+    noProxies.emplace_back(host);
+}
+
 void HttpService::AllowCORS() {
     Use(HttpMiddleware::CORS);
 }

+ 5 - 0
http/server/HttpService.h

@@ -133,6 +133,8 @@ struct HV_EXPORT HttpService {
     // proxy service (that is http.ProxyServer)
     // nginx: location => proxy_pass
     std::map<std::string, std::string, std::greater<std::string>> proxies;
+    StringList  trustProxies;
+    StringList  noProxies;
     int proxy_connect_timeout;
     int proxy_read_timeout;
     int proxy_write_timeout;
@@ -189,6 +191,9 @@ struct HV_EXPORT HttpService {
     // https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
     void AllowCORS();
 
+    // proxy
+    void AddTrustProxy(const char* host);
+    void AddNoProxy(const char* host);
     // forward proxy
     void EnableForwardProxy() { enable_forward_proxy = 1; }
     // reverse proxy