mirror of
https://github.com/moparisthebest/spdylay
synced 2024-11-12 04:25:09 -05:00
Merge pull request #13 from sorced-jim/master
spdycat should fail for failed requests
This commit is contained in:
commit
fabfc0b239
@ -263,13 +263,15 @@ int SpdyEventHandler::submit_file_response(const std::string& status,
|
||||
off_t file_length,
|
||||
spdylay_data_provider *data_prd)
|
||||
{
|
||||
std::string date_str = util::http_date(time(0));
|
||||
std::string content_length = util::to_str(file_length);
|
||||
const char *nv[] = {
|
||||
get_header_field(version_, HD_STATUS).c_str(), status.c_str(),
|
||||
get_header_field(version_, HD_VERSION).c_str(), "HTTP/1.1",
|
||||
"server", SPDYD_SERVER.c_str(),
|
||||
"content-length", util::to_str(file_length).c_str(),
|
||||
"content-length", content_length.c_str(),
|
||||
"cache-control", "max-age=3600",
|
||||
"date", util::http_date(time(0)).c_str(),
|
||||
"date", date_str.c_str(),
|
||||
0, 0,
|
||||
0
|
||||
};
|
||||
@ -286,6 +288,7 @@ int SpdyEventHandler::submit_response
|
||||
const std::vector<std::pair<std::string, std::string> >& headers,
|
||||
spdylay_data_provider *data_prd)
|
||||
{
|
||||
std::string date_str = util::http_date(time(0));
|
||||
const char **nv = new const char*[8+headers.size()*2+1];
|
||||
nv[0] = get_header_field(version_, HD_STATUS).c_str();
|
||||
nv[1] = status.c_str();
|
||||
@ -294,7 +297,7 @@ int SpdyEventHandler::submit_response
|
||||
nv[4] = "server";
|
||||
nv[5] = SPDYD_SERVER.c_str();
|
||||
nv[6] = "date";
|
||||
nv[7] = util::http_date(time(0)).c_str();
|
||||
nv[7] = date_str.c_str();
|
||||
for(int i = 0; i < (int)headers.size(); ++i) {
|
||||
nv[8+i*2] = headers[i].first.c_str();
|
||||
nv[8+i*2+1] = headers[i].second.c_str();
|
||||
|
@ -161,10 +161,13 @@ int communicate(const std::string& host, uint16_t port,
|
||||
}
|
||||
make_non_block(fd);
|
||||
set_tcp_nodelay(fd);
|
||||
Spdylay sc(fd, ssl,
|
||||
spdylay_npn_get_version(reinterpret_cast<const unsigned char*>
|
||||
(next_proto.c_str()), next_proto.size()),
|
||||
callbacks);
|
||||
int spdy_version = spdylay_npn_get_version(
|
||||
reinterpret_cast<const unsigned char*>(next_proto.c_str()),
|
||||
next_proto.size());
|
||||
if (spdy_version <= 0) {
|
||||
return -1;
|
||||
}
|
||||
Spdylay sc(fd, ssl, spdy_version, callbacks);
|
||||
|
||||
nfds_t npollfds = 1;
|
||||
pollfd pollfds[1];
|
||||
@ -243,12 +246,15 @@ int run(char **uris, int n)
|
||||
std::vector<Request> reqvec;
|
||||
std::string prev_host;
|
||||
uint16_t prev_port = 0;
|
||||
int failures = 0;
|
||||
for(int i = 0; i < n; ++i) {
|
||||
uri::UriStruct us;
|
||||
if(uri::parse(us, uris[i])) {
|
||||
if(prev_host != us.host || prev_port != us.port) {
|
||||
if(!reqvec.empty()) {
|
||||
communicate(prev_host, prev_port, reqvec, &callbacks);
|
||||
if (communicate(prev_host, prev_port, reqvec, &callbacks) != 0) {
|
||||
++failures;
|
||||
}
|
||||
reqvec.clear();
|
||||
}
|
||||
prev_host = us.host;
|
||||
@ -258,9 +264,11 @@ int run(char **uris, int n)
|
||||
}
|
||||
}
|
||||
if(!reqvec.empty()) {
|
||||
communicate(prev_host, prev_port, reqvec, &callbacks);
|
||||
if (communicate(prev_host, prev_port, reqvec, &callbacks) != 0) {
|
||||
++failures;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return failures;
|
||||
}
|
||||
|
||||
void print_usage(std::ostream& out)
|
||||
@ -330,8 +338,7 @@ int main(int argc, char **argv)
|
||||
SSL_load_error_strings();
|
||||
SSL_library_init();
|
||||
reset_timer();
|
||||
run(argv+optind, argc-optind);
|
||||
return 0;
|
||||
return run(argv+optind, argc-optind);
|
||||
}
|
||||
|
||||
} // namespace spdylay
|
||||
|
@ -76,6 +76,13 @@ class EndToEndSpdy2Tests(EndToEndSpdyTests):
|
||||
self.assertEquals(0, self.call('/', ['-v', '-3']))
|
||||
self.assertIn('NPN selected the protocol: spdy/3', self.stdout)
|
||||
|
||||
def testFailedRequests(self):
|
||||
self.assertEquals(
|
||||
2, self.call('/', ['https://localhost:25/', 'http://localhost:79']))
|
||||
|
||||
def testOneFailedRequest(self):
|
||||
self.assertEquals(1, subprocess.call([self.client, 'http://localhost:2/']))
|
||||
|
||||
|
||||
class EndToEndSpdy3Tests(EndToEndSpdyTests):
|
||||
@classmethod
|
||||
|
Loading…
Reference in New Issue
Block a user