nghttp: Print error when parsing URI failed

This commit is contained in:
Tatsuhiro Tsujikawa 2015-06-18 18:00:24 +09:00
parent c050fca177
commit 39eb8b8a6b
1 changed files with 27 additions and 21 deletions

View File

@ -2255,17 +2255,24 @@ int run(char **uris, int n) {
http_parser_url u; http_parser_url u;
memset(&u, 0, sizeof(u)); memset(&u, 0, sizeof(u));
auto uri = strip_fragment(uris[i]); auto uri = strip_fragment(uris[i]);
if (http_parser_parse_url(uri.c_str(), uri.size(), 0, &u) == 0 && if (http_parser_parse_url(uri.c_str(), uri.size(), 0, &u) != 0) {
util::has_uri_field(u, UF_SCHEMA)) { std::cerr << "[ERROR] Could not parse URI " << uri << std::endl;
uint16_t port = util::has_uri_field(u, UF_PORT) continue;
}
if (!util::has_uri_field(u, UF_SCHEMA)) {
std::cerr << "[ERROR] URI " << uri << " does not have scheme part"
<< std::endl;
continue;
}
auto port = util::has_uri_field(u, UF_PORT)
? u.port ? u.port
: util::get_default_port(uri.c_str(), u); : util::get_default_port(uri.c_str(), u);
if (!util::fieldeq(uri.c_str(), u, UF_SCHEMA, prev_scheme.c_str()) || if (!util::fieldeq(uri.c_str(), u, UF_SCHEMA, prev_scheme.c_str()) ||
!util::fieldeq(uri.c_str(), u, UF_HOST, prev_host.c_str()) || !util::fieldeq(uri.c_str(), u, UF_HOST, prev_host.c_str()) ||
port != prev_port) { port != prev_port) {
if (!requests.empty()) { if (!requests.empty()) {
if (communicate(prev_scheme, prev_host, prev_port, if (communicate(prev_scheme, prev_host, prev_port, std::move(requests),
std::move(requests), callbacks) != 0) { callbacks) != 0) {
++failures; ++failures;
} }
requests.clear(); requests.clear();
@ -2277,7 +2284,6 @@ int run(char **uris, int n) {
requests.emplace_back(uri, data_fd == -1 ? nullptr : &data_prd, requests.emplace_back(uri, data_fd == -1 ? nullptr : &data_prd,
data_stat.st_size); data_stat.st_size);
} }
}
if (!requests.empty()) { if (!requests.empty()) {
if (communicate(prev_scheme, prev_host, prev_port, std::move(requests), if (communicate(prev_scheme, prev_host, prev_port, std::move(requests),
callbacks) != 0) { callbacks) != 0) {