Added -3, --spdy3 option to spdycat.

This commit is contained in:
Tatsuhiro Tsujikawa 2012-02-26 18:13:56 +09:00
parent 036efc1018
commit ae0bac563e
2 changed files with 24 additions and 8 deletions

View File

@ -61,7 +61,9 @@ struct Config {
bool null_out;
bool remote_name;
bool verbose;
Config():null_out(false), remote_name(false), verbose(false) {}
bool spdy3_only;
Config():null_out(false), remote_name(false), verbose(false),
spdy3_only(false) {}
};
struct Request {
@ -145,6 +147,9 @@ int communicate(const std::string& host, uint16_t port,
return -1;
}
std::string next_proto;
if(config.spdy3_only) {
next_proto = "spdy/3";
}
setup_ssl_ctx(ssl_ctx, &next_proto);
SSL *ssl = SSL_new(ssl_ctx);
if(!ssl) {
@ -275,6 +280,8 @@ void print_help(std::ostream& out)
<< " The filename is dereived from URI. If URI\n"
<< " ends with '/', 'index.html' is used as a\n"
<< " filename. Not implemented yet.\n"
<< " -3, --spdy3 Only use SPDY/3.\n"
<< "\n"
<< std::endl;
}
@ -285,11 +292,12 @@ int main(int argc, char **argv)
{"verbose", no_argument, 0, 'v' },
{"null-out", no_argument, 0, 'n' },
{"remote-name", no_argument, 0, 'O' },
{"spdy3", no_argument, 0, '3' },
{"help", no_argument, 0, 'h' },
{0, 0, 0, 0 }
};
int option_index = 0;
int c = getopt_long(argc, argv, "Onhv", long_options, &option_index);
int c = getopt_long(argc, argv, "Onhv3", long_options, &option_index);
if(c == -1) {
break;
}
@ -306,6 +314,9 @@ int main(int argc, char **argv)
case 'v':
config.verbose = true;
break;
case '3':
config.spdy3_only = true;
break;
case '?':
exit(EXIT_FAILURE);
default:

View File

@ -470,13 +470,18 @@ int select_next_proto_cb(SSL* ssl,
std::cout << std::endl;
}
}
if(spdylay_select_next_protocol(out, outlen, in, inlen) != 1) {
std::cerr << "Server did not advertise spdy/2 or spdy/3 protocol."
<< std::endl;
abort();
std::string& next_proto = *(std::string*)arg;
if(next_proto.empty()) {
if(spdylay_select_next_protocol(out, outlen, in, inlen) != 1) {
std::cerr << "Server did not advertise spdy/2 or spdy/3 protocol."
<< std::endl;
abort();
} else {
next_proto.assign(&(*out)[0], &(*out)[*outlen]);
}
} else {
std::string& next_proto = *(std::string*)arg;
next_proto.assign(&(*out)[0], &(*out)[*outlen]);
*out = (unsigned char*)(next_proto.c_str());
*outlen = next_proto.size();
}
if(ssl_debug) {
std::cout << " NPN selected the protocol: "