MINOR: http: Add `enum etag_type http_get_etag_type(const struct ist)`
http_get_etag_type returns whether a given `etag` is a strong, weak, or invalid
ETag.
diff --git a/include/haproxy/http-t.h b/include/haproxy/http-t.h
index 500fc46..b809710 100644
--- a/include/haproxy/http-t.h
+++ b/include/haproxy/http-t.h
@@ -124,6 +124,12 @@
const struct ist text;
};
+enum http_etag_type {
+ ETAG_INVALID = 0,
+ ETAG_STRONG,
+ ETAG_WEAK
+};
+
#endif /* _HAPROXY_HTTP_T_H */
/*
diff --git a/include/haproxy/http.h b/include/haproxy/http.h
index 1bd9da9..a84f6db 100644
--- a/include/haproxy/http.h
+++ b/include/haproxy/http.h
@@ -104,6 +104,27 @@
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 */