MINOR: http: Add function to get port part of a host
http_get_host_port() function can be used to get the port part of a host. It
will be used to get the port of an uri authority or a host header
value. This function only look for a port starting from the end of the
host. It is the caller responsibility to call it with a valid host value. An
indirect string is returned.
(cherry picked from commit 658f971621839f3b928da099dfe3092b47cbc958)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 70bdf7042e86c7356cb34461148eee97c1fae440)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 0aebb4dc4222edac832ff151671e9f4f15aceac3)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/http.c b/src/http.c
index 0b00e47..08a0070 100644
--- a/src/http.c
+++ b/src/http.c
@@ -468,6 +468,24 @@
}
}
+/* Returns the ist string corresponding to port part (without ':') in the host
+ * <host> or IST_NULL if not found.
+*/
+struct ist http_get_host_port(const struct ist host)
+{
+ char *start, *end, *ptr;
+
+ start = istptr(host);
+ end = istend(host);
+ for (ptr = end; ptr > start && isdigit((unsigned char)*--ptr););
+
+ /* no port found */
+ if (likely(*ptr != ':' || ptr+1 == end || ptr == start))
+ return IST_NULL;
+
+ return istnext(ist2(ptr, end - ptr));
+}
+
/* 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 "://").