.\" Man page generated from reStructuredText. . .TH VMOD_BODYACCESS 3 "" "" "" .SH NAME vmod_bodyaccess \- Varnish Module for request body access . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .\" . .\" NB: This file is machine generated, DO NOT EDIT! . .\" . .\" Edit ./vmod_bodyaccess.vcc and run make instead . .\" . .SH SYNOPSIS .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C import bodyaccess [as name] [from "path"] INT rematch_req_body(STRING re) VOID hash_req_body() INT len_req_body() VOID log_req_body(STRING prefix, INT length) .ft P .fi .UNINDENT .UNINDENT .SH DESCRIPTION .sp Varnish module that lets you access the request body. .\" vcl-start . .sp VCL example: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C vcl 4.0; import std; import bodyaccess; backend default { .host = "192.0.2.11"; .port = "8080"; } sub vcl_recv { if (req.method == "POST") { set req.http.x\-method = req.method; if (std.cache_req_body(110KB)) { set req.http.x\-len = bodyaccess.len_req_body(); set req.http.x\-re = bodyaccess.rematch_req_body("Regex"); bodyaccess.log_req_body("PREFIX:", 3); } } return(hash); } sub vcl_hash { bodyaccess.hash_req_body(); return (lookup); } sub vcl_backend_fetch { set bereq.method = bereq.http.x\-method; } sub vcl_deliver { set resp.http.x\-len = req.http.x\-len; set resp.http.x\-re = req.http.x\-re; } .ft P .fi .UNINDENT .UNINDENT .\" vcl-end . .sp N.B. The request body must be retrieved before doing any operations on it. It can be buffered using the cache_req_body() function from libvmod_std. .sp These functions applies only to standard REST methods. Caching is \fInot\fP allowed on PUT requests. .SS INT rematch_req_body(STRING re) .INDENT 0.0 .TP .B Description Returns \-1 if an error occurrs. Returns 0 if the request body doesn\(aqt contain the string \fIre\fP\&. Returns 1 if the request body contains the string \fIre\fP\&. .sp Note that the comparison is case sensitive and the request body must be buffered. .TP .B Example .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C | std.cache_req_body(1KB); | | if (bodyaccess.rematch_req_body("FOO") == 1) { | std.log("is true"); | } .ft P .fi .UNINDENT .UNINDENT .UNINDENT .SS VOID hash_req_body() .INDENT 0.0 .TP .B Description Adds available request body bytes to the lookup hash key. Note that this function can only be used in vcl_hash and the request body must be buffered. .TP .B Example .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C | sub vcl_recv { | std.cache_req_body(1KB); | } | | sub vcl_hash{ | bodyaccess.hash_req_body(); | } .ft P .fi .UNINDENT .UNINDENT .UNINDENT .SS INT len_req_body() .INDENT 0.0 .TP .B Description Returns the request body length or \-1 if an error occurs. .sp Note that the request body must be buffered. .TP .B Example .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C | std.cache_req_body(1KB); | set req.http.x\-len = bodyaccess.len_req_body(); .ft P .fi .UNINDENT .UNINDENT .UNINDENT .SS VOID log_req_body(STRING prefix="", INT length=200) .INDENT 0.0 .TP .B Description Log the request body to the VSL, making it available for other components. When logging, it takes an optional prefix and a max line length, so the body could be split up across multiple lines as there is a limit to how large a single line can be. .TP .B Example .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C | std.cache_req_body(1KB); | bodyaccess.log_req_body("PREFIX:", 3); .ft P .fi .UNINDENT .UNINDENT .UNINDENT .\" Generated by docutils manpage writer. .