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