MINOR: http: Considere empty ports as valid default ports
In RFC3986#6.2.3, following URIs are considered as equivalent: http://example.com http://example.com/ http://example.com:/ http://example.com:80/ The third one is interristing because the port is empty and it is still considered as a default port. Thus, http_get_host_port() does no longer return IST_NULL when the port is empty. Now, a ist is returned, it points on the first character after the colon (':') with a length of 0. In addition, http_is_default_port() now considers an empty port as a default port, regardless the scheme. This patch must not be backported, if so, without the previous one ("MINOR: h1: Consider empty port as invalid in authority for CONNECT"). (cherry picked from commit 99ade9e0dac03be464ea488e2424351ee0bc2aae) Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
This commit is contained in:
parent
976f02a45d
commit
81cde62d38
11
src/http.c
11
src/http.c
@ -479,7 +479,9 @@ const char *http_get_reason(unsigned int status)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the ist string corresponding to port part (without ':') in the host
|
/* Returns the ist string corresponding to port part (without ':') in the host
|
||||||
* <host> or IST_NULL if not found.
|
* <host>, IST_NULL if no ':' is found or an empty IST if there is no digit. In
|
||||||
|
* the last case, the result is the original ist trimed to 0. So be sure to test
|
||||||
|
* the result length before doing any pointer arithmetic.
|
||||||
*/
|
*/
|
||||||
struct ist http_get_host_port(const struct ist host)
|
struct ist http_get_host_port(const struct ist host)
|
||||||
{
|
{
|
||||||
@ -490,8 +492,10 @@ struct ist http_get_host_port(const struct ist host)
|
|||||||
for (ptr = end; ptr > start && isdigit((unsigned char)*--ptr););
|
for (ptr = end; ptr > start && isdigit((unsigned char)*--ptr););
|
||||||
|
|
||||||
/* no port found */
|
/* no port found */
|
||||||
if (likely(*ptr != ':' || ptr+1 == end || ptr == start))
|
if (likely(*ptr != ':'))
|
||||||
return IST_NULL;
|
return IST_NULL;
|
||||||
|
if (ptr+1 == end)
|
||||||
|
return isttrim(host, 0);
|
||||||
|
|
||||||
return istnext(ist2(ptr, end - ptr));
|
return istnext(ist2(ptr, end - ptr));
|
||||||
}
|
}
|
||||||
@ -503,6 +507,9 @@ struct ist http_get_host_port(const struct ist host)
|
|||||||
*/
|
*/
|
||||||
int http_is_default_port(const struct ist schm, const struct ist port)
|
int http_is_default_port(const struct ist schm, const struct ist port)
|
||||||
{
|
{
|
||||||
|
if (!istlen(port))
|
||||||
|
return 1;
|
||||||
|
|
||||||
if (!isttest(schm))
|
if (!isttest(schm))
|
||||||
return (isteq(port, ist("443")) || isteq(port, ist("80")));
|
return (isteq(port, ist("443")) || isteq(port, ist("80")));
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user