VCLのsubroutines
大まかな流れはVCL(Varnish)の実行の大まかな流れを見て掴むのが良いと思う
docs
built-in subroutinesのdocs
参考
/mrsekut-book-4297119250/689 (A.4.4 サブルーチンとVCL変数)
#WIP
Varnishのeventに応じて行う処理を指定する
引数は取らない
return()は値を返すわけではない
次のsubroutineに移行することを意味する
subroutines間の状態共有には、VCL変数やHTTP headerを使う
global変数を扱う感じになる
同名のsubroutineを複数定義した場合は、両方呼び出される
これは、ファイルを跨いでいても適用されるので注意が必要
overrideされるわけではない
途中でreturnされれば後続のものは呼ばれない
/mrsekut-book-4297119250/704
https://reboot.makeall.net/2013/02/14/what-vcl-on-varnish-02/
client side
vcl_recv
vcl_pipe
vcl_pass
vcl_hash
vcl_purge
vcl_miss
vcl_hit
vcl_deliver
vcl_synth
#??
Backend Side
vcl_backend_fetch
vcl_backend_response
vcl_backend_error
originが4xx/5xxを返した時に呼ばれる(?)
https://varnish-cache.org/docs/6.5/users-guide/vcl-built-in-subs.html#vcl-backend-error
自作する
https://varnish-cache.org/docs/trunk/users-guide/vcl-syntax.html#custom-subroutines
code:vcl
sub pipe_if_local {
if (client.ip ~ local) {
return (pipe);
}
}
命名にvcl_を使ってはならない
関数定義というよりは、処理のグルーピングのイメージ
引数はない
実行後に値を返さない
returnと書いているのに値を返さないのは違和感あるmrsekut.icon
呼ぶ
code:vcl
call pipe_if_local
return (<action>)
#??
関数との見分け方
関数との違い