OpenSDN source code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
http_request.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include "http/http_request.h"
6 
7 #include "base/util.h"
8 
9 using namespace std;
10 
12  method_(static_cast<http_method>(-1)), event_(TcpSession::EVENT_NONE) {
13 }
14 
15 string HttpRequest::ToString() const {
16  if (!url_.empty()) {
17  string repr = http_method_str(method_);
18  repr += " ";
19  repr += url_;
20  return repr;
21  }
22  else return "";
23 }
24 
25 string HttpRequest::UrlPath() const {
26  struct http_parser_url urldata;
27  string path;
28  int res = http_parser_parse_url(url_.c_str(), url_.size(), false, &urldata);
29  if (res == 0 && BitIsSet(urldata.field_set, UF_PATH)) {
30  path = url_.substr(urldata.field_data[UF_PATH].off,
31  urldata.field_data[UF_PATH].len);
32  }
33  return path;
34 }
35 
36 string HttpRequest::UrlQuery() const {
37  struct http_parser_url urldata;
38  string query;
39  int res = http_parser_parse_url(url_.c_str(), url_.size(), false, &urldata);
40  if (res == 0 && BitIsSet(urldata.field_set, UF_QUERY)) {
41  query = url_.substr(urldata.field_data[UF_QUERY].off,
42  urldata.field_data[UF_QUERY].len);
43  }
44  return query;
45 }
http_method method_
Definition: http_request.h:42
std::string url_
Definition: http_request.h:43
std::string ToString() const
Definition: http_request.cc:15
std::string UrlQuery() const
Definition: http_request.cc:36
std::string UrlPath() const
Definition: http_request.cc:25
bool BitIsSet(IntType value, size_t bit)
Definition: util.h:36