Add LocalHostFilter
This commit is contained in:
parent
6c444ec6ca
commit
1011d5211d
|
@ -10,6 +10,6 @@ public:
|
||||||
virtual void asyncHandleHttpRequest(const HttpRequestPtr& req,const std::function<void (const HttpResponsePtr &)>&callback)override;
|
virtual void asyncHandleHttpRequest(const HttpRequestPtr& req,const std::function<void (const HttpResponsePtr &)>&callback)override;
|
||||||
|
|
||||||
PATH_LIST_BEGIN
|
PATH_LIST_BEGIN
|
||||||
PATH_ADD("/json");
|
PATH_ADD("/json","drogon::GetFilter","drogon::LocalHostFilter");
|
||||||
PATH_LIST_END
|
PATH_LIST_END
|
||||||
};
|
};
|
|
@ -85,12 +85,12 @@ int main()
|
||||||
|
|
||||||
drogon::HttpAppFramework::instance().addListener("0.0.0.0",12345);
|
drogon::HttpAppFramework::instance().addListener("0.0.0.0",12345);
|
||||||
drogon::HttpAppFramework::instance().addListener("0.0.0.0",8080);
|
drogon::HttpAppFramework::instance().addListener("0.0.0.0",8080);
|
||||||
#ifdef USE_OPENSSL
|
//#ifdef USE_OPENSSL
|
||||||
//https
|
// //https
|
||||||
drogon::HttpAppFramework::instance().setSSLFiles("server.pem","server.pem");
|
// drogon::HttpAppFramework::instance().setSSLFiles("server.pem","server.pem");
|
||||||
drogon::HttpAppFramework::instance().addListener("0.0.0.0",4430,true);
|
// drogon::HttpAppFramework::instance().addListener("0.0.0.0",4430,true);
|
||||||
drogon::HttpAppFramework::instance().addListener("0.0.0.0",4431,true);
|
// drogon::HttpAppFramework::instance().addListener("0.0.0.0",4431,true);
|
||||||
#endif
|
//#endif
|
||||||
drogon::HttpAppFramework::instance().setThreadNum(4);
|
drogon::HttpAppFramework::instance().setThreadNum(4);
|
||||||
trantor::Logger::setLogLevel(trantor::Logger::TRACE);
|
trantor::Logger::setLogLevel(trantor::Logger::TRACE);
|
||||||
//class function
|
//class function
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <drogon/GetFilter.h>
|
#include <drogon/GetFilter.h>
|
||||||
#include <drogon/PutFilter.h>
|
#include <drogon/PutFilter.h>
|
||||||
#include <drogon/DeleteFilter.h>
|
#include <drogon/DeleteFilter.h>
|
||||||
|
#include <drogon/LocalHostFilter.h>
|
||||||
#include <drogon/version.h>
|
#include <drogon/version.h>
|
||||||
#include <drogon/NotFound.h>
|
#include <drogon/NotFound.h>
|
||||||
#include <drogon/HttpClient.h>
|
#include <drogon/HttpClient.h>
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @author An Tao
|
||||||
|
* @section LICENSE
|
||||||
|
*
|
||||||
|
* Copyright 2018, An Tao. All rights reserved.
|
||||||
|
* Use of this source code is governed by a MIT license
|
||||||
|
* that can be found in the License file.
|
||||||
|
*
|
||||||
|
* @section DESCRIPTION
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <drogon/HttpFilter.h>
|
||||||
|
|
||||||
|
namespace drogon
|
||||||
|
{
|
||||||
|
class LocalHostFilter:public HttpFilter<LocalHostFilter>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LocalHostFilter(){}
|
||||||
|
virtual void doFilter(const HttpRequestPtr& req,
|
||||||
|
const FilterCallback &fcb,
|
||||||
|
const FilterChainCallback &fccb) override ;
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @author An Tao
|
||||||
|
* @section LICENSE
|
||||||
|
*
|
||||||
|
* Copyright 2018, An Tao. All rights reserved.
|
||||||
|
* Use of this source code is governed by a MIT license
|
||||||
|
* that can be found in the License file.
|
||||||
|
*
|
||||||
|
* @section DESCRIPTION
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <drogon/LocalHostFilter.h>
|
||||||
|
#include "HttpResponseImpl.h"
|
||||||
|
using namespace drogon;
|
||||||
|
void LocalHostFilter::doFilter(const HttpRequestPtr& req,
|
||||||
|
const FilterCallback &fcb,
|
||||||
|
const FilterChainCallback &fccb)
|
||||||
|
{
|
||||||
|
if(req->peerAddr().toIp()=="127.0.0.1")
|
||||||
|
{
|
||||||
|
fccb();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto res=drogon::HttpResponse::newNotFoundResponse();
|
||||||
|
fcb(res);
|
||||||
|
}
|
Loading…
Reference in New Issue