Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get request body in varnish

I am currently working on a project based on varnish..

we write vcl and vmod. But the project needs to check the request body. How can I get the post request body in VCL or vmod with a C function?

like image 682
Shaobo Wang Avatar asked Nov 11 '11 08:11

Shaobo Wang


2 Answers

You can do almost everything you want with VCL/VMOD. You should try to call a VMOD subroutine in vcl_recv, and then in C code, write something like below :

  • Use VRT_GetHdr(rec->s, HDR_REQ, "\017Content-Length:"); to read the body length
  • Use HTC_Read(rec->s->htc, body, bodylen);

And enjoy !

You should take a look at existing vmods https://www.varnish-cache.org/vmods, and be free to look into the varnish API sources.

like image 193
Doomsday Avatar answered Dec 06 '22 19:12

Doomsday


I'm not sure you can.

Varnish generally only deals with Req/Resp headers. The bodies are passed along without (much) modification.

I you do find a solution please let me know as I'm interested in this as well.

like image 29
simonmenke Avatar answered Dec 06 '22 18:12

simonmenke