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 : #include "http/http_request.h" 7 : 8 : #include "base/util.h" 9 : 10 : using namespace std; 11 : 12 29 : HttpRequest::HttpRequest() : 13 29 : method_(static_cast<http_method>(-1)), event_(TcpSession::EVENT_NONE) { 14 29 : } 15 : 16 19 : string HttpRequest::ToString() const { 17 19 : if (!url_.empty()) { 18 10 : string repr = http_method_str(method_); 19 10 : repr += " "; 20 10 : repr += url_; 21 10 : return repr; 22 10 : } 23 9 : else return ""; 24 : } 25 : 26 20 : string HttpRequest::UrlPath() const { 27 : struct http_parser_url urldata; 28 20 : string path; 29 20 : int res = http_parser_parse_url(url_.c_str(), url_.size(), false, &urldata); 30 20 : if (res == 0 && BitIsSet(urldata.field_set, UF_PATH)) { 31 20 : path = url_.substr(urldata.field_data[UF_PATH].off, 32 20 : urldata.field_data[UF_PATH].len); 33 : } 34 40 : return path; 35 0 : } 36 : 37 10 : string HttpRequest::UrlQuery() const { 38 : struct http_parser_url urldata; 39 10 : string query; 40 10 : int res = http_parser_parse_url(url_.c_str(), url_.size(), false, &urldata); 41 10 : if (res == 0 && BitIsSet(urldata.field_set, UF_QUERY)) { 42 0 : query = url_.substr(urldata.field_data[UF_QUERY].off, 43 0 : urldata.field_data[UF_QUERY].len); 44 : } 45 20 : return query; 46 0 : }