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.

(cherry picked from commit ca7218aaf073627b665459bd881b2b35a481602a)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit e0d82ea08b2b628d86ea0951ae3e082290810baf)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit ac58076df1c60b8d611ab2790221ce417c61f9f3)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/http.c b/src/http.c
index 08a0070..c10b433 100644
--- a/src/http.c
+++ b/src/http.c
@@ -486,6 +486,20 @@
 	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
  * RFC3986#3.1, otherwise zero. It expects only the scheme and nothing else
  * (particularly not the following "://").