h2load: Uniform handling of URIs from command-line and file
This commit is contained in:
parent
4122920dc6
commit
7097a31968
|
@ -874,24 +874,30 @@ int main(int argc, char **argv)
|
|||
// this URI and ignore those in the remaining URIs if present.
|
||||
http_parser_url u;
|
||||
memset(&u, 0, sizeof(u));
|
||||
auto uri = "";
|
||||
|
||||
std::ifstream uri_file;
|
||||
std::string line_uri;
|
||||
std::vector<std::string> uris;
|
||||
|
||||
if(config.ifile.empty()) {
|
||||
uri = argv[optind];
|
||||
} else {
|
||||
if (std::ifstream(config.ifile)) {
|
||||
uri_file.open(config.ifile, std::ifstream::in);
|
||||
// get first line as first uri
|
||||
std::getline (uri_file, line_uri);
|
||||
uri = (char *)line_uri.c_str();
|
||||
std::copy(&argv[optind], &argv[argc], std::back_inserter(uris));
|
||||
} else {
|
||||
std::ifstream uri_file(config.ifile);
|
||||
|
||||
if(!uri_file) {
|
||||
std::cerr << "cannot read input file: " << config.ifile << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::string line_uri;
|
||||
while(std::getline(uri_file, line_uri)) {
|
||||
uris.push_back(line_uri);
|
||||
}
|
||||
}
|
||||
|
||||
if(uris.empty()) {
|
||||
std::cerr << "no URI available" << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
auto uri = uris[0].c_str();
|
||||
|
||||
if(http_parser_parse_url(uri, strlen(uri), 0, &u) != 0 ||
|
||||
!util::has_uri_field(u, UF_SCHEMA) || !util::has_uri_field(u, UF_HOST)) {
|
||||
|
@ -911,12 +917,10 @@ int main(int argc, char **argv)
|
|||
|
||||
reqlines.push_back(get_reqline(uri, u));
|
||||
|
||||
if (config.ifile.empty()) {
|
||||
++optind;
|
||||
for(int i = optind; i < argc; ++i) {
|
||||
for(auto& s : uris) {
|
||||
memset(&u, 0, sizeof(u));
|
||||
|
||||
auto uri = argv[i];
|
||||
auto uri = s.c_str();
|
||||
|
||||
if(http_parser_parse_url(uri, strlen(uri), 0, &u) != 0) {
|
||||
std::cerr << "invalid URI: " << uri << std::endl;
|
||||
|
@ -925,22 +929,6 @@ int main(int argc, char **argv)
|
|||
|
||||
reqlines.push_back(get_reqline(uri, u));
|
||||
}
|
||||
} else {
|
||||
if(uri_file.is_open()) {
|
||||
// load rest uris from file
|
||||
while(std::getline (uri_file, line_uri)) {
|
||||
auto uri = (char *)line_uri.c_str();
|
||||
|
||||
if(http_parser_parse_url(uri, strlen(uri), 0, &u) != 0) {
|
||||
std::cerr << "invalid URI in input file: " << uri << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
reqlines.push_back(get_reqline(uri, u));
|
||||
}
|
||||
uri_file.close();
|
||||
}
|
||||
}
|
||||
|
||||
if(config.max_concurrent_streams == -1) {
|
||||
config.max_concurrent_streams = reqlines.size();
|
||||
|
@ -957,10 +945,13 @@ int main(int argc, char **argv)
|
|||
shared_nva.emplace_back(":method", "GET");
|
||||
|
||||
//list overridalbe headers
|
||||
std::vector<std::string> override_hdrs = {":host", ":scheme", ":method"};
|
||||
auto override_hdrs = std::vector<std::string>{
|
||||
":authority", ":host", ":method", ":scheme"
|
||||
};
|
||||
|
||||
for(auto& kv : config.custom_headers) {
|
||||
if(std::find(override_hdrs.begin(), override_hdrs.end(), kv.first) != override_hdrs.end()) {
|
||||
if(std::find(std::begin(override_hdrs), std::end(override_hdrs), kv.first)
|
||||
!= std::end(override_hdrs)) {
|
||||
// override header
|
||||
for(auto& nv : shared_nva) {
|
||||
if((nv.name == ":authority" && kv.first == ":host")
|
||||
|
@ -970,7 +961,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
} else {
|
||||
// add additional headers
|
||||
shared_nva.emplace_back(kv.first.c_str(), kv.second.c_str());
|
||||
shared_nva.emplace_back(kv.first, kv.second);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue