nghttpx: Don't forward request if response was commited in mruby hook

This commit is contained in:
Tatsuhiro Tsujikawa 2015-09-02 23:21:45 +09:00
parent f0d41a5ac2
commit e436caf0bb
3 changed files with 19 additions and 6 deletions

View File

@ -307,6 +307,8 @@ int Http2Upstream::on_request_headers(Downstream *downstream,
downstream->set_request_http2_expect_body(true);
}
downstream->inspect_http2_request();
auto upstream = downstream->get_upstream();
auto handler = upstream->get_client_handler();
auto worker = handler->get_worker();
@ -314,8 +316,6 @@ int Http2Upstream::on_request_headers(Downstream *downstream,
mruby_ctx->run_on_request_proc(downstream);
downstream->inspect_http2_request();
downstream->set_request_state(Downstream::HEADER_COMPLETE);
if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
downstream->disable_upstream_rtimer();
@ -323,6 +323,10 @@ int Http2Upstream::on_request_headers(Downstream *downstream,
downstream->set_request_state(Downstream::MSG_COMPLETE);
}
if (downstream->get_response_state() == Downstream::MSG_COMPLETE) {
return 0;
}
start_downstream(downstream);
return 0;

View File

@ -277,8 +277,6 @@ int htp_hdrs_completecb(http_parser *htp) {
auto worker = handler->get_worker();
auto mruby_ctx = worker->get_mruby_context();
mruby_ctx->run_on_request_proc(downstream);
downstream->inspect_http1_request();
if (downstream->get_request_method() != HTTP_CONNECT) {
@ -312,6 +310,14 @@ int htp_hdrs_completecb(http_parser *htp) {
}
}
mruby_ctx->run_on_request_proc(downstream);
downstream->set_request_state(Downstream::HEADER_COMPLETE);
if (downstream->get_response_state() == Downstream::MSG_COMPLETE) {
return 0;
}
rv = downstream->attach_downstream_connection(
upstream->get_client_handler()->get_downstream_connection(downstream));
@ -327,8 +333,6 @@ int htp_hdrs_completecb(http_parser *htp) {
return -1;
}
downstream->set_request_state(Downstream::HEADER_COMPLETE);
return 0;
}
} // namespace

View File

@ -30,6 +30,7 @@
#include "shrpx_downstream.h"
#include "shrpx_config.h"
#include "shrpx_mruby_module.h"
#include "shrpx_downstream_connection.h"
#include "template.h"
namespace shrpx {
@ -77,6 +78,10 @@ int run_request_proc(mrb_state *mrb, Downstream *downstream, RProc *proc) {
downstream->index_request_headers();
}
if (downstream->get_response_state() == Downstream::MSG_COMPLETE) {
downstream->pop_downstream_connection();
}
return rv;
}
} // namespace