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