[multiple] immed connect to backend for streaming
connect to backend (mod_cgi, mod_proxy, mod_sockproxy, mod_wstunnel) for streaming request body without waiting for initial data in request body. Useful for things like websockets when data starts on server-side
This commit is contained in:
parent
5d1aa5d06f
commit
fa5e9b5364
|
@ -2210,12 +2210,22 @@ handler_t gw_handle_subrequest(request_st * const r, void *p_d) {
|
|||
else {
|
||||
handler_t rc = r->con->reqbody_read(r);
|
||||
|
||||
/* XXX: create configurable flag */
|
||||
/* CGI environment requires that Content-Length be set.
|
||||
* Send 411 Length Required if Content-Length missing.
|
||||
* (occurs here if client sends Transfer-Encoding: chunked
|
||||
* and module is flagged to stream request body to backend) */
|
||||
if (-1 == r->reqbody_length && hctx->opts.backend != BACKEND_PROXY){
|
||||
if (hctx->opts.backend == BACKEND_PROXY) {
|
||||
if (hctx->state == GW_STATE_INIT /* ??? < GW_STATE_WRITE ??? */
|
||||
&& rc == HANDLER_WAIT_FOR_EVENT
|
||||
/* streaming flags might not be set yet
|
||||
* if hctx->create_env() not called yet */
|
||||
&& ((r->conf.stream_request_body & FDEVENT_STREAM_REQUEST)
|
||||
|| r->h2_connect_ext))
|
||||
rc = HANDLER_GO_ON;
|
||||
/* connect() to backend proxy w/o waiting for any request body*/
|
||||
}
|
||||
else if (-1 == r->reqbody_length) {
|
||||
/* XXX: create configurable flag */
|
||||
/* CGI environment requires that Content-Length be set.
|
||||
* Send 411 Length Required if Content-Length missing.
|
||||
* (occurs here if client sends Transfer-Encoding: chunked
|
||||
* and module is flagged to stream request body to backend) */
|
||||
return (r->conf.stream_request_body & FDEVENT_STREAM_REQUEST)
|
||||
? http_response_reqbody_read_error(r, 411)
|
||||
: HANDLER_WAIT_FOR_EVENT;
|
||||
|
|
|
@ -1118,16 +1118,16 @@ SUBREQUEST_FUNC(mod_cgi_handle_subrequest) {
|
|||
if (chunkqueue_length(cq) > 65536 - 4096
|
||||
&& (r->conf.stream_request_body & FDEVENT_STREAM_REQUEST_BUFMIN)){
|
||||
r->conf.stream_request_body &= ~FDEVENT_STREAM_REQUEST_POLLIN;
|
||||
if (-1 != hctx->fd) return HANDLER_WAIT_FOR_EVENT;
|
||||
} else {
|
||||
handler_t rc = r->con->reqbody_read(r);
|
||||
if (!chunkqueue_is_empty(cq)) {
|
||||
if (fdevent_fdnode_interest(hctx->fdntocgi) & FDEVENT_OUT) {
|
||||
return (rc == HANDLER_GO_ON) ? HANDLER_WAIT_FOR_EVENT : rc;
|
||||
}
|
||||
}
|
||||
if (rc != HANDLER_GO_ON) return rc;
|
||||
if (rc != HANDLER_GO_ON
|
||||
&& !(r->h2_connect_ext && -1 == hctx->fd
|
||||
&& rc == HANDLER_WAIT_FOR_EVENT))
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
if (-1 == hctx->fd) {
|
||||
/* CGI environment requires that Content-Length be set.
|
||||
* Send 411 Length Required if Content-Length missing.
|
||||
* (occurs here if client sends Transfer-Encoding: chunked
|
||||
|
@ -1137,10 +1137,6 @@ SUBREQUEST_FUNC(mod_cgi_handle_subrequest) {
|
|||
? http_response_reqbody_read_error(r, 411)
|
||||
: HANDLER_WAIT_FOR_EVENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (-1 == hctx->fd) {
|
||||
if (cgi_create_env(r, p, hctx, hctx->cgi_handler)) {
|
||||
r->http_status = 500;
|
||||
r->handler_module = NULL;
|
||||
|
@ -1148,6 +1144,8 @@ SUBREQUEST_FUNC(mod_cgi_handle_subrequest) {
|
|||
return HANDLER_FINISHED;
|
||||
}
|
||||
} else if (!chunkqueue_is_empty(cq)) {
|
||||
if (fdevent_fdnode_interest(hctx->fdntocgi) & FDEVENT_OUT)
|
||||
return HANDLER_WAIT_FOR_EVENT;
|
||||
if (0 != cgi_write_request(hctx, hctx->fdtocgi)) {
|
||||
cgi_connection_close(hctx);
|
||||
return HANDLER_ERROR;
|
||||
|
|
|
@ -494,7 +494,7 @@ static handler_t wstunnel_handler_setup (request_st * const r, plugin_data * con
|
|||
DEBUG_LOG_INFO("WebSocket Version = %d", hybivers);
|
||||
}
|
||||
|
||||
hctx->gw.opts.backend = BACKEND_PROXY; /*(act proxy-like; not used)*/
|
||||
hctx->gw.opts.backend = BACKEND_PROXY; /*(act proxy-like)*/
|
||||
hctx->gw.opts.pdata = hctx;
|
||||
hctx->gw.opts.parse = wstunnel_recv_parse;
|
||||
hctx->gw.stdin_append = wstunnel_stdin_append;
|
||||
|
|
Loading…
Reference in New Issue