# # Copyright (c) 2017- Shohei Tanaka(@xcir) # # File layout and configuration based on libvmod-example # Copyright (c) 2011 Varnish Software AS # request-body access based on libvmod-bodyaccess( https://github.com/aondio/libvmod-bodyaccess ) # $Module parseform 3 Parseform VMOD DESCRIPTION =========== Get POST value $Event event_function Returns a string set by the last VCL event, demonstrating the use of event functions. $Function STRING get(PRIV_TASK, STRING key, STRING glue=", ", ENUM { raw, urlencode } encode="raw") Prototype :: get(STRING key, STRING glue=", ", ENUM { raw, urlencode } encode="raw") Return value STRING Description Get POST value. If POST have multiple-key, join with glue. Only used in vcl_recv. Need to call std.cache_req_body before using this. Support content-type is "application/x-www-form-urlencoded" and "multipart/form-data" and "text/plain". Attention Does not care for binary, if set encode=raw. Output by percent encode, if set encode=urlencoded. Example :: import std; import parseform; sub vcl_recv{ std.cache_req_body(1MB); if(parseform.get("postkey")){ ... } } $Function BLOB get_blob(PRIV_TASK, STRING key, STRING glue=", ", BOOL decode=false) Prototype :: get_blob(STRING key, STRING glue=", ", BOOL decode=false) Return value BLOB Description Get POST value. If POST have multiple-key, join with glue. Only used in vcl_recv. Need to call std.cache_req_body before using this. Support content-type is "application/x-www-form-urlencoded" and "multipart/form-data" and "text/plain". Decode the value, if decode is true and content-type is "application/x-www-form-urlencoded". $Function INT len(PRIV_TASK, STRING key, STRING glue=", ") Prototype :: len(STRING key, STRING glue=", ") Return value INT Description Get POST length. If POST have multiple-key, join with glue. Only used in vcl_recv. Need to call std.cache_req_body before using this. Support content-type is "application/x-www-form-urlencoded" and "multipart/form-data" and "text/plain". Example :: import std; import parseform; sub vcl_recv{ std.cache_req_body(1MB); if(parseform.len("postkey") > 0){ ... } } $Function STRING urlencode(STRING txt) Prototype :: urlencode(STRING txt) Return value STRING Description Encoding to Percent encode Example :: import std; import parseform; sub vcl_recv{ std.cache_req_body(1MB); if(parseform.urlencode("foo.bar.~-_baz") == parseform.get(key="postkey", encode=urlencoded)){ ... } } $Function STRING urldecode(STRING txt) Prototype :: urldecode(STRING txt) Return value STRING Description Decoding to Percent encode Example :: import std; import parseform; sub vcl_recv{ std.cache_req_body(1MB); if(req.http.content-type == "application/x-www-form-urlencoded"){ if("foo bar" == parseform.urldecode(parseform.get("postkey"))){ ... } } } $Function STRING urlencode_blob(BLOB blob) $Function BLOB urldecode_blob(STRING txt)