From 053c760d27692e5a295c5bb6dfde0f21e0852df1 Mon Sep 17 00:00:00 2001 From: antao Date: Thu, 14 Mar 2019 11:25:12 +0800 Subject: [PATCH] Rename the InnerIpFilter class --- examples/simple_example/api_v1_ApiTest.h | 2 +- lib/inc/drogon/HttpAppFramework.h | 2 +- .../{InnerIpFilter.h => IntranetIpFilter.h} | 6 ++-- lib/src/InnerIpFilter.cc | 12 ++++---- lib/src/IntranetIpFilter.cc | 29 +++++++++++++++++++ trantor | 2 +- 6 files changed, 41 insertions(+), 12 deletions(-) rename lib/inc/drogon/{InnerIpFilter.h => IntranetIpFilter.h} (82%) create mode 100644 lib/src/IntranetIpFilter.cc diff --git a/examples/simple_example/api_v1_ApiTest.h b/examples/simple_example/api_v1_ApiTest.h index 1ca5601d..f9ccbd7c 100755 --- a/examples/simple_example/api_v1_ApiTest.h +++ b/examples/simple_example/api_v1_ApiTest.h @@ -10,7 +10,7 @@ class ApiTest : public drogon::HttpController public: METHOD_LIST_BEGIN //use METHOD_ADD to add your custom processing function here; - METHOD_ADD(ApiTest::rootGet, "", "TimeFilter", Get, "drogon::LocalHostFilter", "drogon::InnerIpFilter"); + METHOD_ADD(ApiTest::rootGet, "", "TimeFilter", Get, "drogon::LocalHostFilter", "drogon::IntranetIpFilter"); METHOD_ADD(ApiTest::rootPost, "", Post); METHOD_ADD(ApiTest::get, "/get/{2}/{1}", Get); //path is /api/v1/apitest/get/{arg2}/{arg1} METHOD_ADD(ApiTest::your_method_name, "/{1}/List?P2={2}", Get); //path is /api/v1/apitest/{arg1}/list diff --git a/lib/inc/drogon/HttpAppFramework.h b/lib/inc/drogon/HttpAppFramework.h index ac493bd1..7f492fd2 100755 --- a/lib/inc/drogon/HttpAppFramework.h +++ b/lib/inc/drogon/HttpAppFramework.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/lib/inc/drogon/InnerIpFilter.h b/lib/inc/drogon/IntranetIpFilter.h similarity index 82% rename from lib/inc/drogon/InnerIpFilter.h rename to lib/inc/drogon/IntranetIpFilter.h index 0a470100..92fe49a2 100644 --- a/lib/inc/drogon/InnerIpFilter.h +++ b/lib/inc/drogon/IntranetIpFilter.h @@ -1,6 +1,6 @@ /** * - * InnerIpFilter.h + * IntranetIpFilter.h * An Tao * * Copyright 2018, An Tao. All rights reserved. @@ -18,10 +18,10 @@ namespace drogon { -class InnerIpFilter : public HttpFilter +class IntranetIpFilter : public HttpFilter { public: - InnerIpFilter() {} + IntranetIpFilter() {} virtual void doFilter(const HttpRequestPtr &req, const FilterCallback &fcb, const FilterChainCallback &fccb) override; diff --git a/lib/src/InnerIpFilter.cc b/lib/src/InnerIpFilter.cc index c7154008..f969cc2e 100644 --- a/lib/src/InnerIpFilter.cc +++ b/lib/src/InnerIpFilter.cc @@ -1,6 +1,6 @@ /** * - * InnerIpFilter.cc + * IntranetIpFilter.cc * An Tao * * Copyright 2018, An Tao. All rights reserved. @@ -12,14 +12,14 @@ * */ -#include +#include #include "HttpResponseImpl.h" using namespace drogon; -void InnerIpFilter::doFilter(const HttpRequestPtr &req, - const FilterCallback &fcb, - const FilterChainCallback &fccb) +void IntranetIpFilter::doFilter(const HttpRequestPtr &req, + const FilterCallback &fcb, + const FilterChainCallback &fccb) { - if (req->peerAddr().isInnerIp()) + if (req->peerAddr().isIntranetIp()) { fccb(); return; diff --git a/lib/src/IntranetIpFilter.cc b/lib/src/IntranetIpFilter.cc new file mode 100644 index 00000000..f969cc2e --- /dev/null +++ b/lib/src/IntranetIpFilter.cc @@ -0,0 +1,29 @@ +/** + * + * IntranetIpFilter.cc + * An Tao + * + * Copyright 2018, An Tao. All rights reserved. + * https://github.com/an-tao/drogon + * Use of this source code is governed by a MIT license + * that can be found in the License file. + * + * Drogon + * + */ + +#include +#include "HttpResponseImpl.h" +using namespace drogon; +void IntranetIpFilter::doFilter(const HttpRequestPtr &req, + const FilterCallback &fcb, + const FilterChainCallback &fccb) +{ + if (req->peerAddr().isIntranetIp()) + { + fccb(); + return; + } + auto res = drogon::HttpResponse::newNotFoundResponse(); + fcb(res); +} diff --git a/trantor b/trantor index 29e0b57f..cbda3283 160000 --- a/trantor +++ b/trantor @@ -1 +1 @@ -Subproject commit 29e0b57f6970085886a8c0e702b11237ac5e70d3 +Subproject commit cbda3283552b8fd53de86c7fc645a727d0934644