mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 22:01:31 +02:00
MINOR: http: Add function to detect default port
http_is_default_port() can be used to test if a port is a default HTTP/HTTPS port. A scheme may be specified. In this case, it is used to detect defaults ports, 80 for "http://" and 443 for "https://". Otherwise, with no scheme, both are considered as default ports.
This commit is contained in:
parent
658f971621
commit
ca7218aaf0
@ -37,6 +37,7 @@ enum http_meth_t find_http_meth(const char *str, const int len);
|
|||||||
int http_get_status_idx(unsigned int status);
|
int http_get_status_idx(unsigned int status);
|
||||||
const char *http_get_reason(unsigned int status);
|
const char *http_get_reason(unsigned int status);
|
||||||
struct ist http_get_host_port(const struct ist host);
|
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_validate_scheme(const struct ist schm);
|
int http_validate_scheme(const struct ist schm);
|
||||||
struct ist http_parse_scheme(struct http_uri_parser *parser);
|
struct ist http_parse_scheme(struct http_uri_parser *parser);
|
||||||
struct ist http_parse_authority(struct http_uri_parser *parser, int no_userinfo);
|
struct ist http_parse_authority(struct http_uri_parser *parser, int no_userinfo);
|
||||||
|
14
src/http.c
14
src/http.c
@ -496,6 +496,20 @@ struct ist http_get_host_port(const struct ist host)
|
|||||||
return istnext(ist2(ptr, end - ptr));
|
return istnext(ist2(ptr, end - ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Return non-zero if the port <port> is a default port. If the scheme <schm> is
|
||||||
|
* set, it is used to detect default ports (HTTP => 80 and HTTPS => 443)
|
||||||
|
* port. Otherwise, both are considered as default ports.
|
||||||
|
*/
|
||||||
|
int http_is_default_port(const struct ist schm, const struct ist port)
|
||||||
|
{
|
||||||
|
if (!isttest(schm))
|
||||||
|
return (isteq(port, ist("443")) || isteq(port, ist("80")));
|
||||||
|
else
|
||||||
|
return (isteq(port, ist("443")) && isteqi(schm, ist("https://"))) ||
|
||||||
|
(isteq(port, ist("80")) && isteqi(schm, ist("http://")));
|
||||||
|
}
|
||||||
|
|
||||||
/* Returns non-zero if the scheme <schm> is syntactically correct according to
|
/* Returns non-zero if the scheme <schm> is syntactically correct according to
|
||||||
* RFC3986#3.1, otherwise zero. It expects only the scheme and nothing else
|
* RFC3986#3.1, otherwise zero. It expects only the scheme and nothing else
|
||||||
* (particularly not the following "://").
|
* (particularly not the following "://").
|
||||||
|
Loading…
x
Reference in New Issue
Block a user