5

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?

Tommy Andersen
  • 7,165
  • 1
  • 31
  • 50
StevenWang
  • 3,625
  • 4
  • 30
  • 40

2 Answers2

6

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.

Doomsday
  • 2,650
  • 25
  • 33
1

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.

simonmenke
  • 2,819
  • 19
  • 28