shrpx: Check the fatal error inside downstream http-parser callback

This commit is contained in:
Tatsuhiro Tsujikawa 2012-07-16 23:55:08 +09:00
parent f56cfc920e
commit a95981f3da
3 changed files with 25 additions and 11 deletions

View File

@ -521,7 +521,10 @@ int htp_hdrs_completecb(http_parser *htp)
downstream->set_response_minor(htp->http_minor);
downstream->set_response_connection_close(!http_should_keep_alive(htp));
downstream->set_response_state(Downstream::HEADER_COMPLETE);
downstream->get_upstream()->on_downstream_header_complete(downstream);
if(downstream->get_upstream()->on_downstream_header_complete(downstream)
!= 0) {
return -1;
}
if(downstream->tunnel_established()) {
downstream->get_downstream_connection()->set_tunneling_timeout();
@ -578,9 +581,8 @@ int htp_bodycb(http_parser *htp, const char *data, size_t len)
Downstream *downstream;
downstream = reinterpret_cast<Downstream*>(htp->data);
downstream->get_upstream()->on_downstream_body
return downstream->get_upstream()->on_downstream_body
(downstream, reinterpret_cast<const uint8_t*>(data), len);
return 0;
}
} // namespace
@ -591,9 +593,7 @@ int htp_msg_completecb(http_parser *htp)
downstream = reinterpret_cast<Downstream*>(htp->data);
downstream->set_response_state(Downstream::MSG_COMPLETE);
downstream->get_upstream()->on_downstream_body_complete(downstream);
return 0;
return downstream->get_upstream()->on_downstream_body_complete(downstream);
}
} // namespace

View File

@ -591,7 +591,10 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream)
LOG(INFO) << "Upstream https response headers\n" << hdrs;
}
evbuffer *output = bufferevent_get_output(handler_->get_bev());
evbuffer_add(output, hdrs.c_str(), hdrs.size());
if(evbuffer_add(output, hdrs.c_str(), hdrs.size()) != 0) {
LOG(FATAL) << "evbuffer_add() failed";
return -1;
}
return 0;
}
@ -604,7 +607,10 @@ int HttpsUpstream::on_downstream_body(Downstream *downstream,
char chunk_size_hex[16];
rv = snprintf(chunk_size_hex, sizeof(chunk_size_hex), "%X\r\n",
static_cast<unsigned int>(len));
evbuffer_add(output, chunk_size_hex, rv);
if(evbuffer_add(output, chunk_size_hex, rv) != 0) {
LOG(FATAL) << "evbuffer_add() failed";
return -1;
}
}
evbuffer_add(output, data, len);
if(downstream->get_chunked_response()) {
@ -617,7 +623,10 @@ int HttpsUpstream::on_downstream_body_complete(Downstream *downstream)
{
if(downstream->get_chunked_response()) {
evbuffer *output = bufferevent_get_output(handler_->get_bev());
evbuffer_add(output, "0\r\n\r\n", 5);
if(evbuffer_add(output, "0\r\n\r\n", 5) != 0) {
LOG(FATAL) << "evbuffer_add() failed";
return -1;
}
}
if(ENABLE_LOG) {
LOG(INFO) << "Downstream on_downstream_body_complete";

View File

@ -699,8 +699,13 @@ int SpdyUpstream::on_downstream_header_complete(Downstream *downstream)
data_prd.source.ptr = downstream;
data_prd.read_callback = spdy_data_read_callback;
spdylay_submit_response(session_, downstream->get_stream_id(), nv,
&data_prd);
int rv;
rv = spdylay_submit_response(session_, downstream->get_stream_id(), nv,
&data_prd);
if(rv != 0) {
LOG(FATAL) << "spdylay_submit_response() failed";
return -1;
}
delete [] nv;
return 0;
}