From f74e824c7b46a143a0155e43103cb89d9fecdee9 Mon Sep 17 00:00:00 2001 From: Matthew Rick Date: Fri, 26 Jun 2020 16:40:56 -0500 Subject: [PATCH] Allows charset in content-type header --- Dockerfile | 20 +++++++++++++++++ src/tests/test05.vtc | 52 ++++++++++++++++++++++++++++++++++++++++++++ src/vmod_parseform.c | 12 +++++----- 3 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 Dockerfile create mode 100644 src/tests/test05.vtc diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8369057 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM ubuntu:bionic + +RUN apt-get update && \ + apt-get install -y \ + curl \ + gnupg \ + apt-transport-https + +RUN echo "deb https://packagecloud.io/varnishcache/varnish60lts/ubuntu/ bionic main" > /etc/apt/sources.list.d/varnishcache_varnish60lts.list \ + echo "deb-src https://packagecloud.io/varnishcache/varnish60lts/ubuntu/ bionic main" >> /etc/apt/sources.list.d/varnishcache_varnish60lts.list + +RUN curl -L https://packagecloud.io/varnishcache/varnish60lts/gpgkey > key.txt && \ + apt-key add key.txt && \ + apt-get update + +RUN apt-get install -y \ + libtool \ + automake \ + docutils-common \ + varnish-dev diff --git a/src/tests/test05.vtc b/src/tests/test05.vtc new file mode 100644 index 0000000..0af2b0b --- /dev/null +++ b/src/tests/test05.vtc @@ -0,0 +1,52 @@ +varnishtest "with charset" + +server s1 { + rxreq + expect req.http.t1 == "1" + expect req.http.t2 == "123" + expect req.http.t3 == "" + expect req.http.t6 == "1" + expect req.http.l1 == "1" + expect req.http.l2 == "3" + expect req.http.l3 == "0" + txresp + rxreq + expect req.http.t1 == "1" + expect req.http.t2 == "123" + expect req.http.t3 == "" + expect req.http.t6 == "1" + expect req.http.l1 == "1" + expect req.http.l2 == "3" + expect req.http.l3 == "0" + txresp +} -start + +varnish v1 -vcl+backend { + import std; + import ${vmod_parseform}; + + + sub vcl_recv { + std.cache_req_body(1MB); + set req.http.t1 = parseform.get("a"); + set req.http.t2 = parseform.get("aa"); + set req.http.t3 = parseform.get("aaa"); + set req.http.t4 = parseform.get(key="a", glue="*******"); + set req.http.t5 = parseform.get(key="aa", encode=urlencode); + set req.http.t6 = parseform.get("A"); + set req.http.l1 = parseform.len("a"); + set req.http.l2 = parseform.len("aa"); + set req.http.l3 = parseform.len("aaa"); + return(pass); + } +} -start + + +client c1 { + txreq -url "/" -req "POST" -hdr "Content-Type: application/x-www-Form-urlencoded; charset=UTC-8" -body "a=1&aa=123" + rxresp + txreq -url "/" -req "POST" -hdr "Content-Type: text/plain; charset=UTC-8" -body "a=1\r\naa=123" + rxresp +} + +client c1 -run diff --git a/src/vmod_parseform.c b/src/vmod_parseform.c index 7881d8b..ce77d8b 100644 --- a/src/vmod_parseform.c +++ b/src/vmod_parseform.c @@ -485,21 +485,21 @@ vmod_get_blob(VRT_CTX, struct vmod_priv *priv, VCL_STRING key, VCL_STRING glue, memset(nr, 0, sizeof *nr); return nr; } - + const struct vmod_priv *ret = NULL; - + if (priv->priv == NULL) getbody(ctx, &priv); - + const char *ctype= VRT_GetHdr(ctx, &vmod_priv_parseform_contenttype); - - if(!strcasecmp(ctype, "application/x-www-form-urlencoded")){ + + if(!strncasecmp(ctype, "application/x-www-form-urlencoded", 33)){ ret = search_urlencoded(ctx, key, glue, ((struct vmod_priv_parseform *)priv->priv)->vsb); if(ret->len > 0 && decode){ ret = urldecode(ctx, ret->priv); } }else if(strlen(ctype) > 19 && !strncasecmp(ctype, "multipart/form-data", 19)){ ret = search_multipart (ctx, key, glue, ((struct vmod_priv_parseform *)priv->priv)->vsb); - }else if(!strcasecmp(ctype, "text/plain")){ + }else if(!strncasecmp(ctype, "text/plain", 10)){ ret = search_plain (ctx, key, glue, ((struct vmod_priv_parseform *)priv->priv)->vsb); }else{ struct vmod_priv *nr = NULL;