]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: Add helper functions to trim spaces and tabs
authorRemi Tricot-Le Breton <rlebreton@haproxy.com>
Wed, 23 Dec 2020 17:13:48 +0000 (18:13 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Dec 2020 16:18:00 +0000 (17:18 +0100)
Add two helper functions that trim leading or trailing spaces and
horizontal tabs from an ist string.

include/haproxy/http.h
src/http.c

index fb47abdd454d28479872b2d296b47dcaddde6f35..582a666471c5e4cfd273c5d603ab620e2a8583c6 100644 (file)
@@ -59,6 +59,9 @@ int http_parse_status_val(const struct ist value, struct ist *status, struct ist
 
 int http_compare_etags(struct ist etag1, struct ist etag2);
 
+struct ist http_trim_leading_spht(struct ist value);
+struct ist http_trim_trailing_spht(struct ist value);
+
 /*
  * Given a path string and its length, find the position of beginning of the
  * query string. Returns NULL if no query string is found in the path.
index 22a5a141817ecac8b552b1f4f233767590d48811..d331699568747a521ce180727bc4bf2fc4115da7 100644 (file)
@@ -1074,3 +1074,34 @@ int http_compare_etags(struct ist etag1, struct ist etag2)
 
        return isteq(etag1, etag2);
 }
+
+
+/*
+ * Trim leading space or horizontal tab characters from <value> string.
+ * Returns the trimmed string.
+ */
+struct ist http_trim_leading_spht(struct ist value)
+{
+       struct ist ret = value;
+
+       while (ret.len && HTTP_IS_SPHT(ret.ptr[0])) {
+               ++ret.ptr;
+               --ret.len;
+       }
+
+       return ret;
+}
+
+/*
+ * Trim trailing space or horizontal tab characters from <value> string.
+ * Returns the trimmed string.
+ */
+struct ist http_trim_trailing_spht(struct ist value)
+{
+       struct ist ret = value;
+
+       while (ret.len && HTTP_IS_SPHT(ret.ptr[-1]))
+               --ret.len;
+
+       return ret;
+}