> Am 17.02.2022 um 11:49 schrieb Ruediger Pluem <rpl...@apache.org>:
> 
> 
> 
> On 2/17/22 11:06 AM, ic...@apache.org wrote:
>> Author: icing
>> Date: Thu Feb 17 10:06:31 2022
>> New Revision: 1898146
>> 
>> URL: http://svn.apache.org/viewvc?rev=1898146&view=rev
>> Log:
>>  *) mod_http2: preserve the port number given in a HTTP/1.1
>>     request that was Upgraded to HTTP/2. Fixes PR65881.
>> 
>> 
>> Added:
>>    httpd/httpd/trunk/changes-entries/pr65881.txt
>>    httpd/httpd/trunk/test/modules/http2/test_502_proxy_port.py
>> Modified:
>>    httpd/httpd/trunk/modules/http2/h2_request.c
>>    httpd/httpd/trunk/test/modules/http2/htdocs/cgi/hello.py
>> 
> 
>> 
>> Modified: httpd/httpd/trunk/modules/http2/h2_request.c
>> URL: 
>> http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/http2/h2_request.c?rev=1898146&r1=1898145&r2=1898146&view=diff
>> ==============================================================================
>> --- httpd/httpd/trunk/modules/http2/h2_request.c (original)
>> +++ httpd/httpd/trunk/modules/http2/h2_request.c Thu Feb 17 10:06:31 2022
>> @@ -90,12 +90,25 @@ apr_status_t h2_request_rcreate(h2_reque
>>         return APR_EINVAL;
>>     }
>> 
>> -    if (!ap_strchr_c(authority, ':') && r->server && r->server->port) {
>> -        apr_port_t defport = apr_uri_port_of_scheme(scheme);
>> -        if (defport != r->server->port) {
>> -            /* port info missing and port is not default for scheme: append 
>> */
>> -            authority = apr_psprintf(pool, "%s:%d", authority,
>> -                                     (int)r->server->port);
>> +    /* The authority we carry in h2_request is the 'authority' part of
>> +     * the URL for the request. r->hostname has stripped any port info that
>> +     * might have been present. Do we need to add it?
>> +     */
>> +    if (!ap_strchr_c(authority, ':')) {
>> +        if (r->parsed_uri.port_str) {
>> +            /* Yes, it was there, add it again. */
>> +            authority = apr_psprintf(pool, "%s:%s", authority, 
>> r->parsed_uri.port_str);
> 
> Performance nitpick. Wouldn't it be faster to do
> 
> authority = apr_pstrcat(pool, authority, ":", r->parsed_uri.port_str, NULL);
> 

Good point. I'll bring that in. Thanks.

>> +        }
>> +        else if (!r->parsed_uri.hostname && r->server && r->server->port) {
>> +            /* If there was no hostname in the parsed URL, the URL was 
>> relative.
>> +             * In that case, we restore port from our server->port, if it
>> +             * is known and not the default port for the scheme. */
>> +            apr_port_t defport = apr_uri_port_of_scheme(scheme);
>> +            if (defport != r->server->port) {
>> +                /* port info missing and port is not default for scheme: 
>> append */
>> +                authority = apr_psprintf(pool, "%s:%d", authority,
>> +                                         (int)r->server->port);
>> +            }
>>         }
>>     }
>> 
>> 
> 
> Regards
> 
> RĂ¼diger

Reply via email to