07-09-07 06:13 AM
[ https://issues.apache.org/jira/brow...action_12511033 ]
Graham Dumpleton commented on MODPYTHON-238:
--------------------------------------------
Setting req.chunked to 0 by itself doesn't actually disable chunking. It is
all because of some weird code in modules/http/http_protocol.c which gets ca
lled on first call to write() and which starts with:
if ((r->connection->keepalive != AP_CONN_CLOSE)
&& ((r->status == HTTP_NOT_MODIFIED)
|| (r->status == HTTP_NO_CONTENT)
|| r->header_only
|| apr_table_get(r->headers_out, "Content-Length")
|| ap_find_last_token(r->pool,
apr_table_get(r->headers_out,
"Transfer-Encoding"),
"chunked")
|| ((r->proto_num >= HTTP_VERSION(1,1))
&& (r->chunked = 1))) /* THIS CODE IS CORRECT, see above. */
&& r->server->keep_alive
&& (r->server->keep_alive_timeout > 0)
&& ((r->server->keep_alive_max == 0)
|| (r->server->keep_alive_max > r->connection->keepalives))
&& !ap_status_drops_connection(r->status)
&& !wimpy
&& !ap_find_token(r->pool, conn, "close")
&& (!apr_table_get(r->subprocess_env, "nokeepalive")
|| apr_table_get(r->headers_in, "Via"))
&& ((ka_sent = ap_find_token(r->pool, conn, "keep-alive"))
|| (r->proto_num >= HTTP_VERSION(1,1)))) {
Thus, if r->connection->keepalive is not AP_CONN_CLOSE, it will overwrite r-
>chunked as a side affect of the if condition.
Thus, only way to turn off chunking is to set connection to close as well as
turn chunking to off. Ie.,
r->connection->keepalive = apache.AP_CONN_CLOSE
r->chunked = 0
If you don't care whether chunking is used or not and just want to ensure co
nnection is closed, would instead use:
r->connection->keepalive = apache.AP_CONN_CLOSE
or (I think):
r->subprocess_env['keepalive'] = "0"
or:
r->headers_out['Connection'] = 'Close'
All up, all I am doing is making writable things at C API level that module
writer may want to change. How they are used is governed by Apache and not c
hanging that. Frankly, some of this stuff is real black magic. :-(
> req.connection.keepalive should be writable
> -------------------------------------------
>
> Key: MODPYTHON-238
> URL: https://issues.apache.org/jira/browse/MODPYTHON-238
> Project: mod_python
> Issue Type: Improvement
> Components: core
> Affects Versions: 3.3.1
> Reporter: Graham Dumpleton
> Priority: Minor
>
> The attribute req.connection.keepalive should be writable. This would allo
w handlers to use:
> req.connection.keepalive = apache.AP_CONN_CLOSE
> Doing this before any data is written has the effect of disabling keepalive and al
so turning off chunked encoding for response content when no content length has been
supplied.
[ Post a follow-up to this message ]
|