Skip to content

Commit

Permalink
Allows charset in content-type header
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-null-matt committed Jun 26, 2020
1 parent 84742ba commit f74e824
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
52 changes: 52 additions & 0 deletions src/tests/test05.vtc
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions src/vmod_parseform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f74e824

Please # to comment.