Commit 89ee2b31 by Amir Aharon

add headers to evpp implementation

parent 4494ebbc
......@@ -91,6 +91,15 @@ void EvppRequest::ExecuteInLoop() {
goto failed;
}
/**
* add custom headers
*/
if (!headers_map_.empty()){
for (auto entry : headers_map_){
evhttp_add_header(req->output_headers, entry.first.c_str(), entry.second.c_str());
}
}
if (!body_.empty()) {
//req_type = EVHTTP_REQ_POST;
if (evbuffer_add(req->output_buffer, body_.c_str(), body_.size())) {
......
......@@ -56,6 +56,13 @@ public:
void set_retry_interval(Duration d) {
retry_interval_ = d;
}
void add_header(const std::string& header, const std::string& value){
headers_map_[header] = value;
}
void add_headers(std::map<std::string,std::string>& headers_map){
headers_map_.insert(headers_map.begin(), headers_map.end());
}
private:
static void HandleResponse(struct evhttp_request* r, void* v);
void HandleResponse(struct evhttp_request* r);
......@@ -72,6 +79,7 @@ private:
std::shared_ptr<Conn> conn_;
EvppHandler handler_;
evhttp_cmd_type req_type_;
std::map<std::string,std::string> headers_map_;
// The retried times
int retried_ = 0;
......@@ -88,6 +96,9 @@ typedef std::shared_ptr<EvppRequest> EvppRequestPtr;
class GetEvppRequest : public EvppRequest {
public:
GetEvppRequest(EventLoop* loop, const std::string& url, const std::string& body, Duration timeout)
: EvppRequest(loop, EVHTTP_REQ_GET,url, body, timeout) {}
GetEvppRequest(ConnPool* pool, EventLoop* loop, const std::string& uri_with_param)
: EvppRequest(pool, loop, EVHTTP_REQ_GET, uri_with_param, empty_) {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment