Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #ifndef __HTTP_REQUEST_H__ 7 : #define __HTTP_REQUEST_H__ 8 : 9 : #include <map> 10 : #include <string> 11 : 12 : #include "io/tcp_session.h" 13 : #include "http_parser/http_parser.h" 14 : 15 : class HttpRequest { 16 : public: 17 : typedef std::map<std::string, std::string> HeaderMap; 18 : 19 : HttpRequest(); 20 : 21 10 : void SetMethod(http_method method) { method_ = method; } 22 : http_method GetMethod() const { return method_; } 23 : // clobbers argument 24 19 : void SetUrl(std::string *url) { 25 19 : url_.swap(*url); 26 19 : } 27 50 : void PushHeader(const std::string &key, const std::string &value) { 28 50 : headers_.insert(make_pair(key, value)); 29 50 : } 30 0 : void SetBody(const char *data, size_t length) { 31 0 : body_.append(data, length); 32 0 : } 33 9 : void SetEvent(enum TcpSession::Event event) { event_ = event; } 34 : 35 : std::string ToString() const; 36 : 37 : std::string UrlPath() const; 38 : std::string UrlQuery() const; 39 : const HeaderMap & Headers() const { return headers_; } 40 : const std::string & Body() const { return body_; } 41 0 : TcpSession::Event Event() const { return event_; } 42 : private: 43 : http_method method_; 44 : std::string url_; 45 : HeaderMap headers_; 46 : std::string body_; 47 : TcpSession::Event event_; // used when the request indicates an event 48 : }; 49 : 50 : #endif