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 45254e0..fdc714e 100644 --- a/src/vmod_parseform.c +++ b/src/vmod_parseform.c @@ -504,14 +504,14 @@ vmod_get_blob(VRT_CTX, struct vmod_priv *priv, VCL_STRING key, VCL_STRING glue, 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->blob); } }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 vrt_blob *nr = NULL;