[core] prep mod transitions to transparent proxy

prep mod_proxy,mod_fastcgi,mod_scgi for transition to transparent proxy
personal/stbuehler/mod-csrf
Glenn Strauss 6 years ago
parent dfc1603c4b
commit 316e959b4d

@ -691,6 +691,9 @@ static int cgi_write_request(server *srv, handler_ctx *hctx, int fd) {
if (cq->bytes_out == (off_t)con->request.content_length) {
/* sent all request body input */
/* (future: must defer close()
* if might later upgrade protocols
* and then have more data to send) */
/* close connection to the cgi-script */
if (-1 == hctx->fdtocgi) { /*(received request body sent in initial send to pipe buffer)*/
--srv->cur_fds;

@ -1980,7 +1980,13 @@ static void fcgi_stdin_append(server *srv, connection *con, handler_ctx *hctx, i
fcgi_header(&(header), FCGI_STDIN, request_id, weWant, 0);
chunkqueue_append_mem(hctx->wb, (const char *)&header, sizeof(header));
hctx->wb_reqlen += sizeof(header);
if (-1 != hctx->wb_reqlen) {
if (hctx->wb_reqlen >= 0) {
hctx->wb_reqlen += sizeof(header);
} else {
hctx->wb_reqlen -= sizeof(header);
}
}
if (hctx->conf.debug > 10) {
log_error_write(srv, __FILE__, __LINE__, "soso", "tosend:", offset, "/", req_cqlen);
@ -1992,6 +1998,9 @@ static void fcgi_stdin_append(server *srv, connection *con, handler_ctx *hctx, i
if (hctx->wb->bytes_in == hctx->wb_reqlen) {
/* terminate STDIN */
/* (future: must defer ending FCGI_STDIN
* if might later upgrade protocols
* and then have more data to send) */
fcgi_header(&(header), FCGI_STDIN, request_id, 0, 0);
chunkqueue_append_mem(hctx->wb, (const char *)&header, sizeof(header));
hctx->wb_reqlen += (int)sizeof(header);
@ -2045,7 +2054,13 @@ static int fcgi_create_env(server *srv, handler_ctx *hctx, int request_id) {
buffer_free(b);
}
hctx->wb_reqlen += con->request.content_length;/* (eventual) (minimal) total request size, not necessarily including all fcgi_headers around content length yet */
if (con->request.content_length) {
/*chunkqueue_append_chunkqueue(hctx->wb, con->request_content_queue);*/
if (con->request.content_length > 0)
hctx->wb_reqlen += con->request.content_length;/* (eventual) (minimal) total request size, not necessarily including all fcgi_headers around content length yet */
else /* as-yet-unknown total request size (Transfer-Encoding: chunked)*/
hctx->wb_reqlen = -hctx->wb_reqlen;
}
fcgi_stdin_append(srv, con, hctx, request_id);
return 0;
@ -2519,7 +2534,7 @@ static handler_t fcgi_write_request(server *srv, handler_ctx *hctx) {
fcgi_set_state(srv, hctx, FCGI_STATE_READ);
} else {
off_t wblen = hctx->wb->bytes_in - hctx->wb->bytes_out;
if (hctx->wb->bytes_in < hctx->wb_reqlen && wblen < 65536 - 16384) {
if ((hctx->wb->bytes_in < hctx->wb_reqlen || hctx->wb_reqlen < 0) && wblen < 65536 - 16384) {
/*(con->conf.stream_request_body & FDEVENT_STREAM_REQUEST)*/
if (!(con->conf.stream_request_body & FDEVENT_STREAM_REQUEST_POLLIN)) {
con->conf.stream_request_body |= FDEVENT_STREAM_REQUEST_POLLIN;
@ -2612,7 +2627,7 @@ SUBREQUEST_FUNC(mod_fastcgi_handle_subrequest) {
if (hctx->fcgi_mode != FCGI_AUTHORIZER
&& (0 == hctx->wb->bytes_in
? con->state == CON_STATE_READ_POST
: hctx->wb->bytes_in < hctx->wb_reqlen)) {
: (hctx->wb->bytes_in < hctx->wb_reqlen || hctx->wb_reqlen < 0))) {
/*(64k - 4k to attempt to avoid temporary files
* in conjunction with FDEVENT_STREAM_REQUEST_BUFMIN)*/
if (hctx->wb->bytes_in - hctx->wb->bytes_out > 65536 - 4096
@ -2622,6 +2637,13 @@ SUBREQUEST_FUNC(mod_fastcgi_handle_subrequest) {
} else {
handler_t r = connection_handle_read_post_state(srv, con);
chunkqueue *req_cq = con->request_content_queue;
#if 0 /*(not reached since we send 411 Length Required below)*/
if (hctx->wb_reqlen < -1 && con->request.content_length >= 0) {
/* (completed receiving Transfer-Encoding: chunked) */
hctx->wb_reqlen = -hctx->wb_reqlen + con->request.content_length;
fcgi_stdin_append(srv, con, hctx, hctx->request_id);
}
#endif
if (0 != hctx->wb->bytes_in && !chunkqueue_is_empty(req_cq)) {
fcgi_stdin_append(srv, con, hctx, hctx->request_id);
if (fdevent_event_get_interest(srv->ev, hctx->fd) & FDEVENT_OUT) {

@ -1293,11 +1293,12 @@ static int proxy_create_env(server *srv, handler_ctx *hctx) {
chunkqueue_append_buffer(hctx->wb, b);
buffer_free(b);
/* body */
if (con->request.content_length) {
chunkqueue_append_chunkqueue(hctx->wb, con->request_content_queue);
hctx->wb_reqlen += con->request.content_length;/* (eventual) total request size */
if (con->request.content_length > 0)
hctx->wb_reqlen += con->request.content_length; /* total req size */
else /* as-yet-unknown total request size (Transfer-Encoding: chunked)*/
hctx->wb_reqlen = -hctx->wb_reqlen;
}
return 0;
@ -1425,7 +1426,7 @@ static handler_t proxy_write_request(server *srv, handler_ctx *hctx) {
proxy_set_state(srv, hctx, PROXY_STATE_READ);
} else {
off_t wblen = hctx->wb->bytes_in - hctx->wb->bytes_out;
if (hctx->wb->bytes_in < hctx->wb_reqlen && wblen < 65536 - 16384) {
if ((hctx->wb->bytes_in < hctx->wb_reqlen || hctx->wb_reqlen < 0) && wblen < 65536 - 16384) {
/*(con->conf.stream_request_body & FDEVENT_STREAM_REQUEST)*/
if (!(con->conf.stream_request_body & FDEVENT_STREAM_REQUEST_POLLIN)) {
con->conf.stream_request_body |= FDEVENT_STREAM_REQUEST_POLLIN;
@ -1543,7 +1544,7 @@ SUBREQUEST_FUNC(mod_proxy_handle_subrequest) {
if (0 == hctx->wb->bytes_in
? con->state == CON_STATE_READ_POST
: hctx->wb->bytes_in < hctx->wb_reqlen) {
: (hctx->wb->bytes_in < hctx->wb_reqlen || hctx->wb_reqlen < 0)) {
/*(64k - 4k to attempt to avoid temporary files
* in conjunction with FDEVENT_STREAM_REQUEST_BUFMIN)*/
if (hctx->wb->bytes_in - hctx->wb->bytes_out > 65536 - 4096
@ -1553,6 +1554,12 @@ SUBREQUEST_FUNC(mod_proxy_handle_subrequest) {
} else {
handler_t r = connection_handle_read_post_state(srv, con);
chunkqueue *req_cq = con->request_content_queue;
#if 0 /*(not reached since we send 411 Length Required below)*/
if (hctx->wb_reqlen < -1 && con->request.content_length >= 0) {
/* (completed receiving Transfer-Encoding: chunked) */
hctx->wb_reqlen = -hctx->wb_reqlen + con->request.content_length;
}
#endif
if (0 != hctx->wb->bytes_in && !chunkqueue_is_empty(req_cq)) {
chunkqueue_append_chunkqueue(hctx->wb, req_cq);
if (fdevent_event_get_interest(srv->ev, hctx->fd) & FDEVENT_OUT) {

@ -1673,7 +1673,10 @@ static int scgi_create_env(server *srv, handler_ctx *hctx) {
if (con->request.content_length) {
chunkqueue_append_chunkqueue(hctx->wb, con->request_content_queue);
hctx->wb_reqlen += con->request.content_length;/* (eventual) total request size */
if (con->request.content_length > 0)
hctx->wb_reqlen += con->request.content_length; /* total req size */
else /* as-yet-unknown total request size (Transfer-Encoding: chunked)*/
hctx->wb_reqlen = -hctx->wb_reqlen;
}
return 0;
@ -2015,7 +2018,7 @@ static handler_t scgi_write_request(server *srv, handler_ctx *hctx) {
scgi_set_state(srv, hctx, FCGI_STATE_READ);
} else {
off_t wblen = hctx->wb->bytes_in - hctx->wb->bytes_out;
if (hctx->wb->bytes_in < hctx->wb_reqlen && wblen < 65536 - 16384) {
if ((hctx->wb->bytes_in < hctx->wb_reqlen || hctx->wb_reqlen < 0) && wblen < 65536 - 16384) {
/*(con->conf.stream_request_body & FDEVENT_STREAM_REQUEST)*/
if (!(con->conf.stream_request_body & FDEVENT_STREAM_REQUEST_POLLIN)) {
con->conf.stream_request_body |= FDEVENT_STREAM_REQUEST_POLLIN;
@ -2134,7 +2137,7 @@ SUBREQUEST_FUNC(mod_scgi_handle_subrequest) {
if (0 == hctx->wb->bytes_in
? con->state == CON_STATE_READ_POST
: hctx->wb->bytes_in < hctx->wb_reqlen) {
: (hctx->wb->bytes_in < hctx->wb_reqlen || hctx->wb_reqlen < 0)) {
/*(64k - 4k to attempt to avoid temporary files
* in conjunction with FDEVENT_STREAM_REQUEST_BUFMIN)*/
if (hctx->wb->bytes_in - hctx->wb->bytes_out > 65536 - 4096
@ -2144,6 +2147,12 @@ SUBREQUEST_FUNC(mod_scgi_handle_subrequest) {
} else {
handler_t r = connection_handle_read_post_state(srv, con);
chunkqueue *req_cq = con->request_content_queue;
#if 0 /*(not reached since we send 411 Length Required below)*/
if (hctx->wb_reqlen < -1 && con->request.content_length >= 0) {
/* (completed receiving Transfer-Encoding: chunked) */
hctx->wb_reqlen = -hctx->wb_reqlen + con->request.content_length;
}
#endif
if (0 != hctx->wb->bytes_in && !chunkqueue_is_empty(req_cq)) {
chunkqueue_append_chunkqueue(hctx->wb, req_cq);
if (fdevent_event_get_interest(srv->ev, hctx->fd) & FDEVENT_OUT) {

Loading…
Cancel
Save