]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: Add `enum etag_type http_get_etag_type(const struct ist)`
authorTim Duesterhus <tim@bastelstu.be>
Thu, 22 Oct 2020 08:36:24 +0000 (10:36 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Thu, 22 Oct 2020 14:02:29 +0000 (16:02 +0200)
http_get_etag_type returns whether a given `etag` is a strong, weak, or invalid
ETag.

include/haproxy/http-t.h
include/haproxy/http.h

index 500fc46d5ccda4ae4c78bf33e26c7c56a02a1bf9..b809710b96cfd980436ee6083c35d4b321fa3693 100644 (file)
@@ -124,6 +124,12 @@ struct http_method_desc {
        const struct ist text;
 };
 
+enum http_etag_type {
+       ETAG_INVALID = 0,
+       ETAG_STRONG,
+       ETAG_WEAK
+};
+
 #endif /* _HAPROXY_HTTP_T_H */
 
 /*
index 1bd9da9adbc9551e1f2503c89ef35d85ffe5da40..a84f6db45592beb8fb7ed3af3e2d80d3c30c4332 100644 (file)
@@ -104,6 +104,27 @@ static inline int http_language_range_match(const char *range, int range_len,
        return tag == tend;
 }
 
+static inline enum http_etag_type http_get_etag_type(const struct ist etag)
+{
+       /* An ETag must be at least 2 characters. */
+       if (etag.len < 2)
+               return ETAG_INVALID;
+
+       /* The last character must be a `"`. */
+       if (etag.ptr[etag.len - 1] != '"')
+               return ETAG_INVALID;
+
+       /* If the ETag starts with a `"` then it is a strong ETag. */
+       if (etag.ptr[0] == '"')
+               return ETAG_STRONG;
+
+       /* If the ETag starts with `W/"` then it is a weak ETag. */
+       if (istnmatch(etag, ist("W/\""), 3))
+               return ETAG_WEAK;
+
+       return ETAG_INVALID;
+}
+
 
 #endif /* _HAPROXY_HTTP_H */