Skip to content

Commit

Permalink
Cherry pick f74e824 from varnish61
Browse files Browse the repository at this point in the history
  • Loading branch information
pronovic committed Apr 20, 2023
1 parent caed081 commit 3ab0c0e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
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
4 changes: 2 additions & 2 deletions src/vmod_parseform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3ab0c0e

Please sign in to comment.