当前位置:网站首页>2020-09-21 referer字符串切分 boost gateway代码组织层次
2020-09-21 referer字符串切分 boost gateway代码组织层次
2022-06-29 09:10:00 【qqq2018】
gateway的referer流量验证
字符串切分的优化
上一篇中的字符串用空格分割的代码,可以用boost::split()替代。
boost::split()函数原型:
template<typename SequenceSequenceT, typename RangeT, typename PredicateT>
SequenceSequenceT &
split(SequenceSequenceT & Result, RangeT && Input, PredicateT Pred,
token_compress_mode_type eCompress = token_compress_off);
说人话就是(输出,输入,用来切分的字符,是否把用来切分的相邻字符压缩成一个用于切分的单位)
//test_boost.cpp
//-----------------------
#include <iostream>
#include <vector>
#include <boost/algorithm/string.hpp>
bool IsRefererInBlacklist(const std::string& header_referer) {
std::string header_referer_black_list = "";
header_referer_black_list = "https://www.baidu.com/ https://www.hhh.com/ goajgopahdoj a";
std::vector<std::string> urls;
boost::split(urls, header_referer_black_list, boost::is_any_of(" "));
int num=urls.size();
for(int i=0;i<num;i++){
//std::string url : urls) {
std::string url=urls[i];
if (header_referer == url) {
return true;
}
}
return false;
}
int main()
{
std::cout << IsRefererInBlacklist("https://www.baidu.com/") << std::endl;
std::cout << IsRefererInBlacklist("https://www.hhh.com/") << std::endl;
std::cout << IsRefererInBlacklist("goajgopahdoj") << std::endl;
std::cout << IsRefererInBlacklist("a") << std::endl;
std::cout << IsRefererInBlacklist("https://www.bai.com/") << std::endl;
}
其他注意
referer的url是经过encode的,所有黑名单中也应该存encode后的url
目录结构
test_project
BLADE_ROOT(空)
thirdparty
boost(boost源码,直接从gateway中copy过来的)
source
BUILD(代码在下边)
test_boost.cpp(代码在上边)
# BUILD
# 只有头文件就不用写deps了,blade会让工程知道#include是从BLADE_ROOT开始找路径的
# ---------------
cc_binary(
name = 'test_boost',
srcs = [
'test_boost.cpp',
],
)
拓展:安装boost:
boost大都是header only的。
只要把boost源码放到thirdparty文件夹中即可
gateway组织结构
namespace gateway{
class BidRequestHandler()
// 调用结构
ProcessBidRequest()
//想插入在这,应该把ProcessBidRequest重载吗
shared_ptr<BidRequest> bid_request = handler->ParseBidRequest();
bool ret = handler->CallServices(request, bid_request, ads_req, ads_resp, fill_data_arr, err_msg);
err_msg = PrepareCallAds(request, bid_request, ads_req);
ads_req = GetAdsRequest(*bid_request);
ads_resp = GetAdsResponse(ads_req);
shared_ptr<FillData> fill_data = RenderCallbackData(*bid_request,*ads_req,*ads_resp,i);
handler->WriteBidResponse(fill_data_arr, response)
// 声明
public:
static bool ProcessBidRequest(const shared_ptr<HttpRequest> request, shared_ptr<HttpResponse> response);
virtual shared_ptr<BidRequest> ParseBidRequest() = 0;
virtual bool CallServices(const shared_ptr<HttpRequest> request,shared_ptr<BidRequest>& bid_request,shared_ptr<rtb::AdsRequest>& ads_req,shared_ptr<rtb::AdsResponse>& ads_resp, std::vector<shared_ptr<FillData> >& fill_data_arr,string& err_msg);
protect:
std::string PrepareCallAds(const shared_ptr<HttpRequest> request,shared_ptr<BidRequest> bid_request,shared_ptr<rtb::AdsRequest>& ads_req);
public:
virtual shared_ptr<rtb::AdsRequest> GetAdsRequest(const BidRequest& bid_request);
virtual shared_ptr<rtb::AdsResponse> GetAdsResponse(shared_ptr<rtb::AdsRequest> ad_server_req_arr);
virtual shared_ptr<FillData> RenderCallbackData(BidRequest& bid_request,rtb::AdsRequest& ads_request,rtb::AdsResponse& ads_response,size_t index);
virtual bool WriteBidResponse(vector<shared_ptr<FillData> > fill_data_arr,shared_ptr<HttpResponse> http_response) = 0;
class RecommendRequestHandler : public BidRequestHandler
public:
shared_ptr<BidRequest> ParseBidRequest();
bool WriteBidResponse(vector<shared_ptr<FillData> > fill_datas,shared_ptr<HttpResponse> http_response) {
return true;}
}
边栏推荐
- Student addition / deletion gaih
- kdevelop新建工程
- JS获取手机型号和系统版本
- Closed door cultivation (24) shallow understanding of cross domain problems
- After aikuai is installed or reset, the PC or mobile terminal cannot obtain IP
- Simplicity studio does not recognize the new JLINK V9 solution
- Reading notes on how to connect the network - Web server request and response (IV)
- Automatic Multi-Organ SegmVentation on Abdominal CT With Dense V-Networks
- 《网络是怎么样连接的》读书笔记 - WEB服务端请求和响应(五)
- 367. effective complete square dichotomy
猜你喜欢

通用分页框架

GD32F4xx 以太網芯片(enc28j60)驅動移植

CROSSFORMER: A VERSATILE VISION TRANSFORMER BASED ON CROSS-SCALE ATTENTION

In the future of Business Intelligence BI, how do you view the ai+bi model?

遍历vector容器中的对象的方式
![[Huawei certification] the most complete and selected question bank in hcia-datacom history (with answer analysis)](/img/d4/f5ea847573433f7ca7bd429f57e40a.png)
[Huawei certification] the most complete and selected question bank in hcia-datacom history (with answer analysis)

基于PyQt5和Qt Designer的简易加法计算器的制作

Introduction to Chang'an chain data storage and construction of MySQL storage environment

Factory mode

1424. 对角线遍历 II
随机推荐
基于PyQt5和Qt Designer的简易加法计算器的制作
长安链GO语言智能合约编写与编译
Chapter 12 signals (II) - examples of producers and consumers
Pytorch summary learning series - broadcast mechanism
Automatic 3D Detection and Segmentation of Head and Neck Cancer from MRI Data.
【技术开发】酒精测试仪解决方案开发设计
UE4 blueprint modify get a copy in array to reference
长安链GO语言智能合约环境搭建及使用
基於PyQt5和Qt Designer的簡易加法計算器的制作
Gd32f4xx Ethernet Chip (ENC28J60) Drive transplantation
UE4 动画重定向
Es error nonodeavailableexception[none of the configured nodes are available:[.127.0.0.1}{127.0.0.1:9300]
Leetcode skimming -- teponacci sequence
Reading notes on how to connect the network - Web server request and response (IV)
Matlab tips (21) matrix analysis -- partial least squares regression
In the era of data processing, data quality construction is the way for enterprises to survive
Implementation of multi key state machine based on STM32 standard library
Self cultivation (XXI) servlet life cycle, service method source code analysis, thread safety issues
UE4 material UV texture does not stretch with model scale
SPI drive of lsm6dsl