.\" Man page generated from reStructuredText .\" by the Docutils 0.23 manpage writer. . . .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 .. .TH "vmod_bodyaccess" "3" "" "" .SH Name vmod_bodyaccess \- Varnish Module for request body access .\" . .\" 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 .EX import bodyaccess [as name] [from \(dqpath\(dq] INT rematch_req_body(REGEX re) VOID hash_req_body() INT len_req_body() VOID log_req_body(STRING prefix, INT length) .EE .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 .EX vcl 4.0; import std; import bodyaccess; backend default { .host = \(dq192.0.2.11\(dq; .port = \(dq8080\(dq; } sub vcl_recv { if (req.method == \(dqPOST\(dq) { 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(\(dqRegex\(dq); bodyaccess.log_req_body(\(dqPREFIX:\(dq, 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; } .EE .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(REGEX 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 .EX | std.cache_req_body(1KB); | | if (bodyaccess.rematch_req_body(\(dqFOO\(dq) == 1) { | std.log(\(dqis true\(dq); | } .EE .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 .EX | sub vcl_recv { | std.cache_req_body(1KB); | } | | sub vcl_hash{ | bodyaccess.hash_req_body(); | } .EE .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 .EX | std.cache_req_body(1KB); | set req.http.x\-len = bodyaccess.len_req_body(); .EE .UNINDENT .UNINDENT .UNINDENT .SS VOID log_req_body(STRING prefix=\(dq\(dq, 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 .EX | std.cache_req_body(1KB); | bodyaccess.log_req_body(\(dqPREFIX:\(dq, 3); .EE .UNINDENT .UNINDENT .UNINDENT .\" End of generated man page.