Skip to content

Commit f74e824

Browse files
committed
Allows charset in content-type header
1 parent 84742ba commit f74e824

3 files changed

Lines changed: 78 additions & 6 deletions

File tree

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM ubuntu:bionic
2+
3+
RUN apt-get update && \
4+
apt-get install -y \
5+
curl \
6+
gnupg \
7+
apt-transport-https
8+
9+
RUN echo "deb https://packagecloud.io/varnishcache/varnish60lts/ubuntu/ bionic main" > /etc/apt/sources.list.d/varnishcache_varnish60lts.list \
10+
echo "deb-src https://packagecloud.io/varnishcache/varnish60lts/ubuntu/ bionic main" >> /etc/apt/sources.list.d/varnishcache_varnish60lts.list
11+
12+
RUN curl -L https://packagecloud.io/varnishcache/varnish60lts/gpgkey > key.txt && \
13+
apt-key add key.txt && \
14+
apt-get update
15+
16+
RUN apt-get install -y \
17+
libtool \
18+
automake \
19+
docutils-common \
20+
varnish-dev

src/tests/test05.vtc

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
varnishtest "with charset"
2+
3+
server s1 {
4+
rxreq
5+
expect req.http.t1 == "1"
6+
expect req.http.t2 == "123"
7+
expect req.http.t3 == ""
8+
expect req.http.t6 == "1"
9+
expect req.http.l1 == "1"
10+
expect req.http.l2 == "3"
11+
expect req.http.l3 == "0"
12+
txresp
13+
rxreq
14+
expect req.http.t1 == "1"
15+
expect req.http.t2 == "123"
16+
expect req.http.t3 == ""
17+
expect req.http.t6 == "1"
18+
expect req.http.l1 == "1"
19+
expect req.http.l2 == "3"
20+
expect req.http.l3 == "0"
21+
txresp
22+
} -start
23+
24+
varnish v1 -vcl+backend {
25+
import std;
26+
import ${vmod_parseform};
27+
28+
29+
sub vcl_recv {
30+
std.cache_req_body(1MB);
31+
set req.http.t1 = parseform.get("a");
32+
set req.http.t2 = parseform.get("aa");
33+
set req.http.t3 = parseform.get("aaa");
34+
set req.http.t4 = parseform.get(key="a", glue="*******");
35+
set req.http.t5 = parseform.get(key="aa", encode=urlencode);
36+
set req.http.t6 = parseform.get("A");
37+
set req.http.l1 = parseform.len("a");
38+
set req.http.l2 = parseform.len("aa");
39+
set req.http.l3 = parseform.len("aaa");
40+
return(pass);
41+
}
42+
} -start
43+
44+
45+
client c1 {
46+
txreq -url "/" -req "POST" -hdr "Content-Type: application/x-www-Form-urlencoded; charset=UTC-8" -body "a=1&aa=123"
47+
rxresp
48+
txreq -url "/" -req "POST" -hdr "Content-Type: text/plain; charset=UTC-8" -body "a=1\r\naa=123"
49+
rxresp
50+
}
51+
52+
client c1 -run

src/vmod_parseform.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,21 +485,21 @@ vmod_get_blob(VRT_CTX, struct vmod_priv *priv, VCL_STRING key, VCL_STRING glue,
485485
memset(nr, 0, sizeof *nr);
486486
return nr;
487487
}
488-
488+
489489
const struct vmod_priv *ret = NULL;
490-
490+
491491
if (priv->priv == NULL) getbody(ctx, &priv);
492-
492+
493493
const char *ctype= VRT_GetHdr(ctx, &vmod_priv_parseform_contenttype);
494-
495-
if(!strcasecmp(ctype, "application/x-www-form-urlencoded")){
494+
495+
if(!strncasecmp(ctype, "application/x-www-form-urlencoded", 33)){
496496
ret = search_urlencoded(ctx, key, glue, ((struct vmod_priv_parseform *)priv->priv)->vsb);
497497
if(ret->len > 0 && decode){
498498
ret = urldecode(ctx, ret->priv);
499499
}
500500
}else if(strlen(ctype) > 19 && !strncasecmp(ctype, "multipart/form-data", 19)){
501501
ret = search_multipart (ctx, key, glue, ((struct vmod_priv_parseform *)priv->priv)->vsb);
502-
}else if(!strcasecmp(ctype, "text/plain")){
502+
}else if(!strncasecmp(ctype, "text/plain", 10)){
503503
ret = search_plain (ctx, key, glue, ((struct vmod_priv_parseform *)priv->priv)->vsb);
504504
}else{
505505
struct vmod_priv *nr = NULL;

0 commit comments

Comments
 (0)