summaryrefslogtreecommitdiff
path: root/src/http_header.c
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2020-07-30 12:05:53 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2020-08-02 07:47:42 -0400
commit0fb391c096c8396ac20180ef096bc7c8030bb80c (patch)
tree5e06f99cfa44275518e84f5e90223d759bc79d10 /src/http_header.c
parentd44a26bfa3b61bfad746e2e163c7cc5826c44e06 (diff)
downloadlighttpd-git-0fb391c096c8396ac20180ef096bc7c8030bb80c.tar.gz
[core] http_header_remove_token()
Diffstat (limited to 'src/http_header.c')
-rw-r--r--src/http_header.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/http_header.c b/src/http_header.c
index a4f5a573..4f203b4f 100644
--- a/src/http_header.c
+++ b/src/http_header.c
@@ -97,6 +97,36 @@ int http_header_str_contains_token (const char * const s, const uint32_t slen, c
}
+int http_header_remove_token (buffer * const b, const char * const m, const uint32_t mlen)
+{
+ /*(remove all instance of token from string)*/
+ /*(note: does not handle quoted-string)*/
+ int rc = 0;
+ for (char *s = b->ptr; s; ) {
+ while (*s == ' ' || *s == '\t' || *s == ',') ++s;
+ if (0 == strncasecmp(s, m, mlen)) {
+ s += mlen;
+ if (*s=='\0' || *s==' ' || *s=='\t' || *s==',' || *s==';') {
+ memset(s-mlen, ' ', mlen);
+ while (*s != '\0' && *s != ',') ++s;
+ rc = 1;
+ if (*s == ',') {
+ *s++ = ' ';
+ continue;
+ }
+ else {
+ for (s -= mlen; *s != ',' && s != b->ptr; --s) ;
+ buffer_string_set_length(b, (size_t)(s - b->ptr));
+ break;
+ }
+ }
+ }
+ s = strchr(s, ',');
+ }
+ return rc;
+}
+
+
static inline void http_header_token_append(buffer * const vb, const char * const v, const uint32_t vlen) {
if (!buffer_string_is_empty(vb))
buffer_append_string_len(vb, CONST_STR_LEN(", "));