src: Return StringRef from util::get_uri_field
This commit is contained in:
parent
fe6ccd16da
commit
907eeeda8a
|
@ -1396,7 +1396,7 @@ std::string get_reqline(const char *uri, const http_parser_url &u) {
|
|||
std::string reqline;
|
||||
|
||||
if (util::has_uri_field(u, UF_PATH)) {
|
||||
reqline = util::get_uri_field(uri, u, UF_PATH);
|
||||
reqline = util::get_uri_field(uri, u, UF_PATH).str();
|
||||
} else {
|
||||
reqline = "/";
|
||||
}
|
||||
|
@ -1437,8 +1437,8 @@ bool parse_base_uri(std::string base_uri) {
|
|||
return false;
|
||||
}
|
||||
|
||||
config.scheme = util::get_uri_field(base_uri.c_str(), u, UF_SCHEMA);
|
||||
config.host = util::get_uri_field(base_uri.c_str(), u, UF_HOST);
|
||||
config.scheme = util::get_uri_field(base_uri.c_str(), u, UF_SCHEMA).str();
|
||||
config.host = util::get_uri_field(base_uri.c_str(), u, UF_HOST).str();
|
||||
config.default_port = util::get_default_port(base_uri.c_str(), u);
|
||||
if (util::has_uri_field(u, UF_PORT)) {
|
||||
config.port = u.port;
|
||||
|
|
|
@ -187,7 +187,7 @@ int Request::update_html_parser(const uint8_t *data, size_t len, int fin) {
|
|||
|
||||
std::string Request::make_reqpath() const {
|
||||
std::string path = util::has_uri_field(u, UF_PATH)
|
||||
? util::get_uri_field(uri.c_str(), u, UF_PATH)
|
||||
? util::get_uri_field(uri.c_str(), u, UF_PATH).str()
|
||||
: "/";
|
||||
if (util::has_uri_field(u, UF_QUERY)) {
|
||||
path += '?';
|
||||
|
@ -200,21 +200,20 @@ std::string Request::make_reqpath() const {
|
|||
namespace {
|
||||
// Perform special handling |host| if it is IPv6 literal and includes
|
||||
// zone ID per RFC 6874.
|
||||
std::string decode_host(std::string host) {
|
||||
std::string decode_host(const StringRef &host) {
|
||||
auto zone_start = std::find(std::begin(host), std::end(host), '%');
|
||||
if (zone_start == std::end(host) ||
|
||||
!util::ipv6_numeric_addr(
|
||||
std::string(std::begin(host), zone_start).c_str())) {
|
||||
return host;
|
||||
return host.str();
|
||||
}
|
||||
// case: ::1%
|
||||
if (zone_start + 1 == std::end(host)) {
|
||||
host.pop_back();
|
||||
return host;
|
||||
return StringRef{host.c_str(), host.size() - 1}.str();
|
||||
}
|
||||
// case: ::1%12 or ::1%1
|
||||
if (zone_start + 3 >= std::end(host)) {
|
||||
return host;
|
||||
return host.str();
|
||||
}
|
||||
// If we see "%25", followed by more characters, then decode %25 as
|
||||
// '%'.
|
||||
|
@ -222,9 +221,9 @@ std::string decode_host(std::string host) {
|
|||
? zone_start + 3
|
||||
: zone_start + 1;
|
||||
auto zone_id = util::percent_decode(zone_id_src, std::end(host));
|
||||
host.erase(zone_start + 1, std::end(host));
|
||||
host += zone_id;
|
||||
return host;
|
||||
auto res = std::string(std::begin(host), zone_start + 1);
|
||||
res += zone_id;
|
||||
return res;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
@ -349,7 +348,7 @@ int submit_request(HttpClient *client, const Headers &headers, Request *req) {
|
|||
auto scheme = util::get_uri_field(req->uri.c_str(), req->u, UF_SCHEMA);
|
||||
auto build_headers = Headers{{":method", req->data_prd ? "POST" : "GET"},
|
||||
{":path", path},
|
||||
{":scheme", scheme},
|
||||
{":scheme", scheme.str()},
|
||||
{":authority", client->hostport},
|
||||
{"accept", "*/*"},
|
||||
{"accept-encoding", "gzip, deflate"},
|
||||
|
@ -1255,7 +1254,8 @@ void HttpClient::update_hostport() {
|
|||
if (reqvec.empty()) {
|
||||
return;
|
||||
}
|
||||
scheme = util::get_uri_field(reqvec[0]->uri.c_str(), reqvec[0]->u, UF_SCHEMA);
|
||||
scheme = util::get_uri_field(reqvec[0]->uri.c_str(), reqvec[0]->u, UF_SCHEMA)
|
||||
.str();
|
||||
std::stringstream ss;
|
||||
if (reqvec[0]->is_ipv6_literal_addr()) {
|
||||
// we may have zone ID, which must start with "%25", or "%". RFC
|
||||
|
@ -2381,7 +2381,7 @@ int run(char **uris, int n) {
|
|||
}
|
||||
requests.clear();
|
||||
}
|
||||
prev_scheme = util::get_uri_field(uri.c_str(), u, UF_SCHEMA);
|
||||
prev_scheme = util::get_uri_field(uri.c_str(), u, UF_SCHEMA).str();
|
||||
prev_host = std::move(host);
|
||||
prev_port = port;
|
||||
}
|
||||
|
|
12
src/util.cc
12
src/util.cc
|
@ -591,13 +591,13 @@ bool fieldeq(const char *uri, const http_parser_url &u,
|
|||
return i == len && !t[i];
|
||||
}
|
||||
|
||||
std::string get_uri_field(const char *uri, const http_parser_url &u,
|
||||
http_parser_url_fields field) {
|
||||
if (util::has_uri_field(u, field)) {
|
||||
return std::string(uri + u.field_data[field].off, u.field_data[field].len);
|
||||
} else {
|
||||
return "";
|
||||
StringRef get_uri_field(const char *uri, const http_parser_url &u,
|
||||
http_parser_url_fields field) {
|
||||
if (!util::has_uri_field(u, field)) {
|
||||
return StringRef{};
|
||||
}
|
||||
|
||||
return StringRef{uri + u.field_data[field].off, u.field_data[field].len};
|
||||
}
|
||||
|
||||
uint16_t get_default_port(const char *uri, const http_parser_url &u) {
|
||||
|
|
|
@ -448,8 +448,8 @@ bool fieldeq(const char *uri1, const http_parser_url &u1, const char *uri2,
|
|||
bool fieldeq(const char *uri, const http_parser_url &u,
|
||||
http_parser_url_fields field, const char *t);
|
||||
|
||||
std::string get_uri_field(const char *uri, const http_parser_url &u,
|
||||
http_parser_url_fields field);
|
||||
StringRef get_uri_field(const char *uri, const http_parser_url &u,
|
||||
http_parser_url_fields field);
|
||||
|
||||
uint16_t get_default_port(const char *uri, const http_parser_url &u);
|
||||
|
||||
|
|
Loading…
Reference in New Issue