Skip to content

Commit a29723c

Browse files
committed
let httpd handle CL/TE for non-http handlers
backport r1916769 from trunk: Submitted By: ylavic, covener git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1916777 13f79535-47bb-0310-9956-ffa450edef68
1 parent ee86d1d commit a29723c

9 files changed

+79
-6
lines changed

include/util_script.h

+2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ AP_DECLARE(int) ap_scan_script_header_err_core_ex(request_rec *r, char *buffer,
225225
*/
226226
AP_DECLARE(void) ap_args_to_table(request_rec *r, apr_table_t **table);
227227

228+
#define AP_TRUST_CGILIKE_CL_ENVVAR "ap_trust_cgilike_cl"
229+
228230
#ifdef __cplusplus
229231
}
230232
#endif

modules/aaa/mod_authnz_fcgi.c

+8
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,14 @@ static apr_status_t handle_response(const fcgi_provider_conf *conf,
571571
"parsing -> %d/%d",
572572
fn, status, r->status);
573573

574+
/* FCGI has its own body framing mechanism which we don't
575+
* match against any provided Content-Length, so let the
576+
* core determine C-L vs T-E based on what's actually sent.
577+
*/
578+
if (!apr_table_get(r->subprocess_env, AP_TRUST_CGILIKE_CL_ENVVAR))
579+
apr_table_unset(r->headers_out, "Content-Length");
580+
apr_table_unset(r->headers_out, "Transfer-Encoding");
581+
574582
if (rspbuf) { /* caller wants to see response body,
575583
* if any
576584
*/

modules/generators/mod_cgi.c

+12-3
Original file line numberDiff line numberDiff line change
@@ -967,9 +967,18 @@ static int cgi_handler(request_rec *r)
967967
char sbuf[MAX_STRING_LEN];
968968
int ret;
969969

970-
if ((ret = ap_scan_script_header_err_brigade_ex(r, bb, sbuf,
971-
APLOG_MODULE_INDEX)))
972-
{
970+
ret = ap_scan_script_header_err_brigade_ex(r, bb, sbuf,
971+
APLOG_MODULE_INDEX);
972+
973+
/* xCGI has its own body framing mechanism which we don't
974+
* match against any provided Content-Length, so let the
975+
* core determine C-L vs T-E based on what's actually sent.
976+
*/
977+
if (!apr_table_get(r->subprocess_env, AP_TRUST_CGILIKE_CL_ENVVAR))
978+
apr_table_unset(r->headers_out, "Content-Length");
979+
apr_table_unset(r->headers_out, "Transfer-Encoding");
980+
981+
if (ret != OK) {
973982
ret = log_script(r, conf, ret, dbuf, sbuf, bb, script_err);
974983

975984
/*

modules/generators/mod_cgid.c

+12-3
Original file line numberDiff line numberDiff line change
@@ -1616,9 +1616,18 @@ static int cgid_handler(request_rec *r)
16161616
b = apr_bucket_eos_create(c->bucket_alloc);
16171617
APR_BRIGADE_INSERT_TAIL(bb, b);
16181618

1619-
if ((ret = ap_scan_script_header_err_brigade_ex(r, bb, sbuf,
1620-
APLOG_MODULE_INDEX)))
1621-
{
1619+
ret = ap_scan_script_header_err_brigade_ex(r, bb, sbuf,
1620+
APLOG_MODULE_INDEX);
1621+
1622+
/* xCGI has its own body framing mechanism which we don't
1623+
* match against any provided Content-Length, so let the
1624+
* core determine C-L vs T-E based on what's actually sent.
1625+
*/
1626+
if (!apr_table_get(r->subprocess_env, AP_TRUST_CGILIKE_CL_ENVVAR))
1627+
apr_table_unset(r->headers_out, "Content-Length");
1628+
apr_table_unset(r->headers_out, "Transfer-Encoding");
1629+
1630+
if (ret != OK) {
16221631
ret = log_script(r, conf, ret, dbuf, sbuf, bb, NULL);
16231632

16241633
/*

modules/http/http_filters.c

+12
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,18 @@ static APR_INLINE int check_headers(request_rec *r)
778778
struct check_header_ctx ctx;
779779
core_server_config *conf =
780780
ap_get_core_module_config(r->server->module_config);
781+
const char *val;
782+
783+
if ((val = apr_table_get(r->headers_out, "Transfer-Encoding"))) {
784+
if (apr_table_get(r->headers_out, "Content-Length")) {
785+
apr_table_unset(r->headers_out, "Content-Length");
786+
r->connection->keepalive = AP_CONN_CLOSE;
787+
}
788+
if (!ap_is_chunked(r->pool, val)) {
789+
r->connection->keepalive = AP_CONN_CLOSE;
790+
return 0;
791+
}
792+
}
781793

782794
ctx.r = r;
783795
ctx.strict = (conf->http_conformance != AP_HTTP_CONFORMANCE_UNSAFE);

modules/proxy/ajp_header.c

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "ajp_header.h"
1818
#include "ajp.h"
1919

20+
#include "util_script.h"
21+
2022
APLOG_USE_MODULE(proxy_ajp);
2123

2224
static const char *response_trans_headers[] = {
@@ -669,6 +671,14 @@ static apr_status_t ajp_unmarshal_response(ajp_msg_t *msg,
669671
}
670672
}
671673

674+
/* AJP has its own body framing mechanism which we don't
675+
* match against any provided Content-Length, so let the
676+
* core determine C-L vs T-E based on what's actually sent.
677+
*/
678+
if (!apr_table_get(r->subprocess_env, AP_TRUST_CGILIKE_CL_ENVVAR))
679+
apr_table_unset(r->headers_out, "Content-Length");
680+
apr_table_unset(r->headers_out, "Transfer-Encoding");
681+
672682
return APR_SUCCESS;
673683
}
674684

modules/proxy/mod_proxy_fcgi.c

+9
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,15 @@ static apr_status_t dispatch(proxy_conn_rec *conn, proxy_dir_conf *conf,
779779

780780
status = ap_scan_script_header_err_brigade_ex(r, ob,
781781
NULL, APLOG_MODULE_INDEX);
782+
783+
/* FCGI has its own body framing mechanism which we don't
784+
* match against any provided Content-Length, so let the
785+
* core determine C-L vs T-E based on what's actually sent.
786+
*/
787+
if (!apr_table_get(r->subprocess_env, AP_TRUST_CGILIKE_CL_ENVVAR))
788+
apr_table_unset(r->headers_out, "Content-Length");
789+
apr_table_unset(r->headers_out, "Transfer-Encoding");
790+
782791
/* suck in all the rest */
783792
if (status != OK) {
784793
apr_bucket *tmp_b;

modules/proxy/mod_proxy_scgi.c

+8
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,14 @@ static int pass_response(request_rec *r, proxy_conn_rec *conn)
390390
return status;
391391
}
392392

393+
/* SCGI has its own body framing mechanism which we don't
394+
* match against any provided Content-Length, so let the
395+
* core determine C-L vs T-E based on what's actually sent.
396+
*/
397+
if (!apr_table_get(r->subprocess_env, AP_TRUST_CGILIKE_CL_ENVVAR))
398+
apr_table_unset(r->headers_out, "Content-Length");
399+
apr_table_unset(r->headers_out, "Transfer-Encoding");
400+
393401
conf = ap_get_module_config(r->per_dir_config, &proxy_scgi_module);
394402
if (conf->sendfile && conf->sendfile != scgi_sendfile_off) {
395403
short err = 1;

modules/proxy/mod_proxy_uwsgi.c

+6
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,12 @@ static int uwsgi_response(request_rec *r, proxy_conn_rec * backend,
404404
return HTTP_BAD_GATEWAY;
405405
}
406406

407+
/* T-E wins over C-L */
408+
if (apr_table_get(r->headers_out, "Transfer-Encoding")) {
409+
apr_table_unset(r->headers_out, "Content-Length");
410+
backend->close = 1;
411+
}
412+
407413
if ((buf = apr_table_get(r->headers_out, "Content-Type"))) {
408414
ap_set_content_type(r, apr_pstrdup(r->pool, buf));
409415
}

0 commit comments

Comments
 (0)