On 5/31/22 5:06 PM, ylavic@apache.org wrote:
> Author: ylavic
> Date: Tue May 31 15:06:13 2022
> New Revision: 1901460
>
> URL: http://svn.apache.org/viewvc?rev=1901460&view=rev
> Log:
> mod_proxy: Align ap_proxy_create_hdrbrgd() with 2.4.x's.
>
> In 2.4.x, the copy of r->headers_in is left in r->headers_in for the whole
> function, while the original r->headers_in are restored at the end. This
> is simpler and avoids the r->headers_in <=> saved_headers_in danse when
> calling a function that modifies r->headers_in in place.
>
> Align with 2.4.x, no functional change.
>
>
> Modified:
> httpd/httpd/trunk/modules/proxy/proxy_util.c
>
> Modified: httpd/httpd/trunk/modules/proxy/proxy_util.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/proxy_util.c?rev=1901460&r1=1901459&r2=1901460&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/modules/proxy/proxy_util.c (original)
> +++ httpd/httpd/trunk/modules/proxy/proxy_util.c Tue May 31 15:06:13 2022
> @@ -3939,52 +3942,49 @@ PROXY_DECLARE(int) ap_proxy_create_hdrbr
> * icing: if p indeed lives longer than r->pool, we should allocate
> * all new header values from r->pool as well and avoid leakage.
> */
> - request_headers = apr_table_copy(r->pool, r->headers_in);
> + r->headers_in = apr_table_copy(r->pool, saved_headers_in);
>
> /* We used to send `Host: ` always first, so let's keep it that
> * way. No telling which legacy backend is relying no this.
> */
> if (dconf->preserve_host == 0) {
> - const char *nhost;
> if (ap_strchr_c(uri->hostname, ':')) { /* if literal IPv6 address */
> if (uri->port_str && uri->port != DEFAULT_HTTP_PORT) {
> - nhost = apr_pstrcat(r->pool, "[", uri->hostname, "]:",
> - uri->port_str, NULL);
> + host = apr_pstrcat(r->pool, "[", uri->hostname, "]:",
> + uri->port_str, NULL);
> } else {
> - nhost = apr_pstrcat(r->pool, "[", uri->hostname, "]", NULL);
> + host = apr_pstrcat(r->pool, "[", uri->hostname, "]", NULL);
> }
> } else {
> if (uri->port_str && uri->port != DEFAULT_HTTP_PORT) {
> - nhost = apr_pstrcat(r->pool, uri->hostname, ":",
> - uri->port_str, NULL);
> + host = apr_pstrcat(r->pool, uri->hostname, ":",
> + uri->port_str, NULL);
> } else {
> - nhost = uri->hostname;
> + host = uri->hostname;
> }
> }
> - ap_h1_append_header(header_brigade, r->pool, "Host", nhost);
> - apr_table_unset(request_headers, "Host");
> }
> else {
> /* don't want to use r->hostname, as the incoming header might have a
> * port attached
> */
> - const char* hostname = apr_table_get(request_headers, "Host");
> - if (!hostname) {
> - hostname = r->server->server_hostname;
> + host = saved_host;
> + if (!host) {
> + host = r->server->server_hostname;
> ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(01092)
> "no HTTP 0.9 request (with no host line) "
> "on incoming request and preserve host set "
> "forcing hostname to be %s for uri %s",
> - hostname, r->uri);
> + host, r->uri);
> }
> - ap_h1_append_header(header_brigade, r->pool, "Host", hostname);
> - apr_table_unset(request_headers, "Host");
> }
> + ap_h1_append_header(header_brigade, r->pool, "Host", host);
> + apr_table_unset(r->headers_in, "Host");
This is nothing introduced by this change but something I noticed. If the fixup hook adds back a Host header,
we would sent two Host headers to the backend.
Regards
RĂ¼diger
> Author: ylavic
> Date: Tue May 31 15:06:13 2022
> New Revision: 1901460
>
> URL: http://svn.apache.org/viewvc?rev=1901460&view=rev
> Log:
> mod_proxy: Align ap_proxy_create_hdrbrgd() with 2.4.x's.
>
> In 2.4.x, the copy of r->headers_in is left in r->headers_in for the whole
> function, while the original r->headers_in are restored at the end. This
> is simpler and avoids the r->headers_in <=> saved_headers_in danse when
> calling a function that modifies r->headers_in in place.
>
> Align with 2.4.x, no functional change.
>
>
> Modified:
> httpd/httpd/trunk/modules/proxy/proxy_util.c
>
> Modified: httpd/httpd/trunk/modules/proxy/proxy_util.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/proxy_util.c?rev=1901460&r1=1901459&r2=1901460&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/modules/proxy/proxy_util.c (original)
> +++ httpd/httpd/trunk/modules/proxy/proxy_util.c Tue May 31 15:06:13 2022
> @@ -3939,52 +3942,49 @@ PROXY_DECLARE(int) ap_proxy_create_hdrbr
> * icing: if p indeed lives longer than r->pool, we should allocate
> * all new header values from r->pool as well and avoid leakage.
> */
> - request_headers = apr_table_copy(r->pool, r->headers_in);
> + r->headers_in = apr_table_copy(r->pool, saved_headers_in);
>
> /* We used to send `Host: ` always first, so let's keep it that
> * way. No telling which legacy backend is relying no this.
> */
> if (dconf->preserve_host == 0) {
> - const char *nhost;
> if (ap_strchr_c(uri->hostname, ':')) { /* if literal IPv6 address */
> if (uri->port_str && uri->port != DEFAULT_HTTP_PORT) {
> - nhost = apr_pstrcat(r->pool, "[", uri->hostname, "]:",
> - uri->port_str, NULL);
> + host = apr_pstrcat(r->pool, "[", uri->hostname, "]:",
> + uri->port_str, NULL);
> } else {
> - nhost = apr_pstrcat(r->pool, "[", uri->hostname, "]", NULL);
> + host = apr_pstrcat(r->pool, "[", uri->hostname, "]", NULL);
> }
> } else {
> if (uri->port_str && uri->port != DEFAULT_HTTP_PORT) {
> - nhost = apr_pstrcat(r->pool, uri->hostname, ":",
> - uri->port_str, NULL);
> + host = apr_pstrcat(r->pool, uri->hostname, ":",
> + uri->port_str, NULL);
> } else {
> - nhost = uri->hostname;
> + host = uri->hostname;
> }
> }
> - ap_h1_append_header(header_brigade, r->pool, "Host", nhost);
> - apr_table_unset(request_headers, "Host");
> }
> else {
> /* don't want to use r->hostname, as the incoming header might have a
> * port attached
> */
> - const char* hostname = apr_table_get(request_headers, "Host");
> - if (!hostname) {
> - hostname = r->server->server_hostname;
> + host = saved_host;
> + if (!host) {
> + host = r->server->server_hostname;
> ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(01092)
> "no HTTP 0.9 request (with no host line) "
> "on incoming request and preserve host set "
> "forcing hostname to be %s for uri %s",
> - hostname, r->uri);
> + host, r->uri);
> }
> - ap_h1_append_header(header_brigade, r->pool, "Host", hostname);
> - apr_table_unset(request_headers, "Host");
> }
> + ap_h1_append_header(header_brigade, r->pool, "Host", host);
> + apr_table_unset(r->headers_in, "Host");
This is nothing introduced by this change but something I noticed. If the fixup hook adds back a Host header,
we would sent two Host headers to the backend.
Regards
RĂ¼diger