{"id":10734,"date":"2014-12-17T00:00:56","date_gmt":"2014-12-16T15:00:56","guid":{"rendered":"http:\/\/labs.gree.jp\/blog\/?p=10734"},"modified":"2015-12-11T17:57:51","modified_gmt":"2015-12-11T08:57:51","slug":"varnish%e3%81%a7%e3%83%86%e3%82%b9%e3%83%88%e3%82%b3%e3%83%bc%e3%83%89%e3%82%92%e6%9b%b8%e3%81%93%e3%81%86%ef%bc%81%ef%bd%9e%e5%ae%9f%e8%b7%b5%e7%b7%a8%ef%bd%9e%ef%bc%8b%e3%81%8a%e3%81%be%e3%81%91","status":"publish","type":"post","link":"https:\/\/labs.gree.jp\/blog\/2014\/12\/10734\/","title":{"rendered":"Varnish\u3067\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3092\u66f8\u3053\u3046\uff01\uff5e\u5b9f\u8df5\u7de8\uff5e\uff0bBody\u3092\u8aad\u3082\u3046\uff01"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001Service Reliability\u30c1\u30fc\u30e0\u306e\u3044\u308f\u306a\u3061\u3083\u3093\u3055\u3093(@xcir)\u3067\u3059\u3002<br \/>\n\u5148\u65e5\u3001\u793e\u5185\u3067\u884c\u308f\u308c\u305f<a href=\"http:\/\/labs.gree.jp\/blog\/2014\/12\/12697\/\">\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u30cf\u30c3\u30ab\u30bd\u30f3<\/a>\u3067\u306f\u30c1\u30fc\u30e0\u30de\u30a4\u30ca\u30b95500\u4e07\u3068\u3057\u3066Varnish\u3092\u3044\u308c\u308b\u7c21\u5358\u306a\u304a\u4ed5\u4e8b\u3092\u3057\u3066\u304d\u307e\u3057\u305f\u3002<br \/>\n\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u306f GREE Advent Calendar 2014 17\u65e5\u76ee\u306e\u8a18\u4e8b\u3067\u3059\u3002<\/p>\n<p>\u4ee5\u524d\u3068\u3042\u308b\u52c9\u5f37\u4f1a\u3067<br \/>\n\u300cvarnishtest\u306e\u4f7f\u3044\u65b9\u304c\u3088\u304f\u308f\u304b\u3089\u306a\u3044\u300d<br \/>\n\u300c\u5225\u306e\u30c4\u30fc\u30eb\u3092\u4f7f\u3063\u3066\u30c6\u30b9\u30c8\u3092\u3084\u3063\u3066\u3044\u308b\u300d<br \/>\n\u3068\u3044\u3046\u8a71\u3092\u805e\u304d\u307e\u3057\u305f\u3002<br \/>\nvarnish\u306fvarnishtest\u3068\u3044\u3046\u30c6\u30b9\u30c8\u30c4\u30fc\u30eb\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u3042\u307e\u308a\u5229\u7528\u3055\u308c\u3066\u3044\u306a\u3044\u3088\u3046\u3067\u3059\u3002<br \/>\n\u539f\u56e0\u306f\u3044\u304f\u3064\u304b\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u307e\u305a\u306f\u5b9f\u969b\u306e\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9(VTC)\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n\u4ee5\u4e0b\u306f\u516c\u5f0f\u306erollback\u6a5f\u80fd\u306eVTC\u3067\u3059\u3002<\/p>\n<pre><code>\nvarnishtest \"Test Rollback\"\n\n\nserver s1 {\n    rxreq\n    expect req.url == \"\/foo\"\n    expect req.http.foobar == \"harck-coff\"\n    txresp -status 400\n    accept\n    rxreq\n    expect req.url == \"\/bar\"\n    expect req.http.foobar == \"snark\"\n    txresp -bodylen 5\n} -start\n\nvarnish v1 -vcl+backend {\n    sub vcl_recv {\n        if (req.url == \"\/foo\") {\n            set req.http.foobar = \"harck-coff\";\n        }\n    }\n\n    sub vcl_fetch {\n        if (beresp.status == 400) {\n            rollback;\n            set req.url = \"\/bar\";\n            return (restart);\n        }\n    }\n} -start\n\nclient c1 {\n    txreq -url \"\/foo\" -hdr \"foobar: snark\"\n    rxresp\n} -run\n<\/code><\/pre>\n<p><a href=\"https:\/\/github.com\/varnish\/Varnish-Cache\/blob\/varnish-3.0.6\/bin\/varnishtest\/tests\/c00032.vtc\">https:\/\/github.com\/varnish\/Varnish-Cache\/blob\/varnish-3.0.6\/bin\/varnishtest\/tests\/c00032.vtc<\/a><\/p>\n<p>VTC\u4e2d\u306bVCL\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u306e\u304c\u308f\u304b\u308a\u307e\u3059\u3002<br \/>\nvarnishd\u672c\u4f53\u306e\u30c1\u30a7\u30c3\u30af\u3092\u3059\u308b\u306e\u3067\u3042\u308c\u3070\u7279\u306b\u554f\u984c\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3001<br \/>\nVCL\u306e\u30c6\u30b9\u30c8\u3092\u884c\u3044\u305f\u3044\u5834\u5408\u306bVTC\u4e2d\u306bVCL\u3092\u8a18\u8f09\u3059\u308b\u306e\u306f\u4e0d\u90fd\u5408\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u3067\u306f\u3069\u306e\u3088\u3046\u306b\u66f8\u3051\u3070\u826f\u3044\u306e\u304b\u3068\u3044\u3046\u306e\u3092\u5f0a\u793e\u3067\u306eVCL\u306e\u69cb\u9020\u3092\u7d39\u4ecb\u3057\u3064\u3064\u4e00\u4f8b\u3068\u3057\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u306a\u304avarnishtest\/VTC\u81ea\u4f53\u306b\u3064\u3044\u3066\u306f\u4ee5\u524d\u306e\u8a18\u4e8b\u3067\u3042\u308b\u300c<a href=\"http:\/\/labs.gree.jp\/blog\/2013\/04\/7966\/\" title=\"Varnish\u3067\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3092\u66f8\u3053\u3046\uff01\">Varnish\u3067\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3092\u66f8\u3053\u3046\uff01<\/a>\u300d\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>VCL\u69cb\u9020<\/h3>\n<p>\u5f0a\u793e\u3067\u904b\u7528\u3057\u3066\u3044\u308bVarnish\u306f100\u8d85\u306e\u30c9\u30e1\u30a4\u30f3\u3092\u914d\u4fe1\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u305d\u306e\u305f\u3081\u3001\u30c9\u30e1\u30a4\u30f3\u6bce\u306bvcl_recv\u3092\u3084\u3089vcl_fetch\u306a\u3069\u3092\u66f8\u3044\u3066\u3044\u308b\u3068\u30ad\u30ea\u304c\u3042\u308a\u307e\u305b\u3093\u3002<br \/>\n\u305d\u3053\u3067vcl\u306e\u5404\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u8907\u6570\u5b9a\u7fa9\u3057\u305f\u969b\u306b\u8aad\u307f\u8fbc\u307f\u9806\u306b\u5b9f\u884c\u3055\u308c\u308b\u6a5f\u80fd\uff08<a href=\"http:\/\/blog.xcir.net\/?p=1120\">\u53c2\u7167<\/a>\uff09<br \/>\n\u3068include\u3092\u5229\u7528\u3057\u3001\u3067\u304d\u308b\u3060\u3051\u5171\u901a\u5316\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u5927\u307e\u304b\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5206\u3051\u3066\u3044\u307e\u3059\u3002\u3000<\/p>\n<ul>\n<li>\u5171\u901a\u8a2d\u5b9a<\/li>\n<ul>\n<li>Probe(\u30d8\u30eb\u30b9\u30c1\u30a7\u30c3\u30af)\u3084inline-C\u5411\u3051\u306einclude\u306a\u3069\u306e\u5171\u901a\u5b9a\u7fa9<\/li>\n<li>\u6b63\u898f\u5316\u3084Purge\u306a\u3069<\/li>\n<\/ul>\n<li>\u30ed\u30fc\u30eb\u5225\u8a2d\u5b9a<\/li>\n<ul>\n<li>ACL\u306a\u3069\u304c\u540c\u3058\u30c9\u30e1\u30a4\u30f3\u3092\u307e\u3068\u3081\u305f\u30bf\u30a4\u30d7\u5225\u8a2d\u5b9a<\/li>\n<li>\u7279\u6b8a\u306a\u632f\u308a\u5206\u3051\u30eb\u30fc\u30eb\u3092\u6301\u3064\u30c9\u30e1\u30a4\u30f3\u5225\u8a2d\u5b9a<\/li>\n<li>\u3069\u306e\u30c9\u30e1\u30a4\u30f3\u3092\u30c9\u30e1\u30a4\u30f3\u30fb\u30bf\u30a4\u30d7\u5225\u8a2d\u5b9a\u306b\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3059\u308b\u304b\u306e\u8a2d\u5b9a<\/li>\n<\/ul>\n<\/ul>\n<p>\u3053\u306e\u3088\u3046\u306a\u69cb\u9020\u3092\u53d6\u308b\u3053\u3068\u3067\u57fa\u70b9\u3068\u306a\u308bdefault.vcl\u3068\u5404\u30c9\u30e1\u30a4\u30f3\u6bce\u306e\u8a2d\u5b9a\u91cf\u306f\u975e\u5e38\u306b\u5c11\u306a\u304f\u306a\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\u5f0a\u793e\u3067\u5b9f\u969b\u306b\u7a3c\u50cd\u3057\u3066\u3044\u308bvarnish\u306edefault.vcl\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u8a18\u8ff0\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\uff08\u203b\u8907\u6570\u306e\u30ed\u30fc\u30eb\u304c\u3042\u308b\u306e\u3067\u3059\u3079\u3066\u304c\u3053\u306e\u8a2d\u5b9a\u3067\u306f\u306a\u3044\u3067\u3059\uff09<\/p>\n<pre><code>\n\/\/Load common define\ninclude \"\/etc\/varnish\/common\/common_define.vcl\";\n\n\/\/Load common prefilter\ninclude \"\/etc\/varnish\/common\/common_pre.vcl\";\n\n\/\/load domain subroutine\ninclude \"\/etc\/varnish\/ext.vcl\";\n\n\/\/load RUM subroutine\ninclude \"\/etc\/varnish\/rum.vcl\";\n\ninclude \"\/etc\/varnish\/is.storage.vcl\";\ninclude \"\/etc\/varnish\/if.storage.vcl\";\ninclude \"\/etc\/varnish\/st.storage.vcl\";\n\n\/\/load main vcl\ninclude \"\/etc\/varnish\/main.vcl\";\n\n\/\/Load common postfilter\ninclude \"\/etc\/varnish\/common\/common_post.vcl\";\n\n<\/code><\/pre>\n<p>\u305d\u3057\u3066\u30c9\u30e1\u30a4\u30f3\u30fb\u30bf\u30a4\u30d7\u5225\u8a2d\u5b9a\u306f<\/p>\n<pre><code>\nsub local_type1_recv {\n  \/\/set default backend\n  set req.backend = stor_image;\n\n  \/\/\u30a2\u30af\u30bb\u30b9\u7981\u6b62\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u6307\u5b9a\n  if(req.url !~ \"^\/(css|swf|js|img)\/\") {error 403;}\n}\n<\/code><\/pre>\n<p>\u3068\u6bd4\u8f03\u7684\u30b7\u30f3\u30d7\u30eb\u3067\u3059\u3002<br \/>\n\u307b\u3068\u3093\u3069\u306e\u57fa\u672c\u7684\u306a\u8a2d\u5b9a\u306fcommon_(pre|post).vcl\u3067\u884c\u3063\u3066\u3044\u308b\u305f\u3081\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u3088\u3046\u306b\u5171\u901a\u5316\u3057\u3066\u3044\u308b\u3068\u91cd\u8981\u306a\u306e\u304c\u30c6\u30b9\u30c8\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u7279\u5b9a\u306e\u30c9\u30e1\u30a4\u30f3\u3078\u306eACL\u306e\u8ffd\u52a0\u306a\u3069\u306f\u5f71\u97ff\u7bc4\u56f2\u306f\u305d\u306e\u30c9\u30e1\u30a4\u30f3\u3060\u3051\u3068\u306a\u308a\u307e\u3059\u304c\u3001<br \/>\n\u5171\u901a\u90e8\u5206\u306b\u6a5f\u80fd\u3092\u5897\u3084\u305d\u3046\u3068\u3059\u308b\u3068\u5e83\u7bc4\u56f2\u306b\u5f71\u97ff\u3092\u53ca\u307c\u3059\u305f\u3081\u30c6\u30b9\u30c8\u304c\u7121\u3044\u3068\u78ba\u8a8d\u306f\u975e\u5e38\u306b\u53b3\u3057\u3044\u3067\u3059\u3002<br \/>\n\u6b21\u306b\u5f0a\u793e\u3067\u306eVTC\u306e\u69cb\u9020\u3068\u66f8\u304d\u65b9\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h3>VTC\u69cb\u9020<\/h3>\n<p>VTC\u3082\u5171\u901a\u8a2d\u5b9a\u3068\u30c9\u30e1\u30a4\u30f3\u30fb\u30bf\u30a4\u30d7\u5225\u8a2d\u5b9a\u3054\u3068\u306b\u5206\u3051\u3066\u30c6\u30b9\u30c8\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\nVTC\u4e2d\u306b\u30c6\u30b9\u30c8\u3092\u884c\u3044\u305f\u3044VCL\u3092\u66f8\u304b\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306b\u306finclude\u3092\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u5b9f\u969b\u306b\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h4>\u5171\u901a\u8a2d\u5b9a<\/h4>\n<p><b>vtc\u30b5\u30f3\u30d7\u30eb<\/b><\/p>\n<pre><code>\nserver s1 {\n    rxreq\n    txresp -hdr \"Set-Cookie: num=123456; expires=Sun, 10-Jun-2001 12:00:00 GMT; path=\/HTTP\/\" -body \"aaaaaa\"\n    expect req.http.cookie == <undef>;\n} -start\nvarnish v1 \\\n    -arg \"-pvcc_err_unref=off\" \\\n    -vcl+backend {\n        include \"${gree_confpath}\/[\u5171\u901a\u8a2d\u5b9a].vcl\";\n        sub vcl_recv{return(pass);}\n    } -start\nclient c1 {\n    txreq -url \"\/\" -hdr \"Cookie: Customer=\\\"Tarou_YAMADA\\\";\"\n    rxresp\n    expect resp.status                   == 200\n    expect resp.http.set-cookie          == <undef>;\n} -run\n<\/code><\/pre>\n<p><b>\u30c6\u30b9\u30c8\u5b9f\u884c\u30b3\u30de\u30f3\u30c9<\/b><\/p>\n<pre><code>\nsudo varnishtest -Dgree_confpath=\/etc\/varnish *.vtc\n<\/code><\/pre>\n<p>\u3053\u306eVTC\u3067\u306f\u4ee5\u4e0b\u306e\u30c1\u30a7\u30c3\u30af\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<ul>\n<li>client\u304b\u3089cookie\u3092\u9001\u3063\u305f\u5834\u5408\u306b\u6d88\u53bb\u3055\u308c\u308b<\/li>\n<li>server\u304b\u3089set_cookie\u3092\u9001\u3063\u305f\u5834\u5408\u306b\u6d88\u53bb\u3055\u308c\u308b<\/li>\n<\/ul>\n<p>\u30dd\u30a4\u30f3\u30c8\u306freturn(pass)\u3092\u6307\u5b9a\u3057\u3066\u3044\u308b\u3053\u3068\u3068\u8d77\u52d5\u30d1\u30e9\u30e1\u30fc\u30bf\u3067vcc_err_unref=off\u3092\u6307\u5b9a\u3057\u3066\u3044\u308b\u3053\u3068\u3067\u3059\u3002<br \/>\nvarnishtest\u306f\u5b9f\u969b\u306bvarnish\u3092\u8d77\u52d5\u3057\u3066\u884c\u3046\u306e\u3067\u3001\u5f53\u7136\u306a\u304c\u3089\u30ad\u30e3\u30c3\u30b7\u30e5\u3055\u308c\u308b\u3053\u3068\u304c\u6709\u308a\u307e\u3059\u3002<br \/>\n\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u524d\u63d0\u306e\u30c6\u30b9\u30c8\u306e\u5834\u5408\u3067\u3042\u308c\u3070\u610f\u8b58\u3057\u3066\u305d\u306e\u3088\u3046\u306b\u66f8\u304d\u307e\u3059\u304c\u3001<br \/>\n\u305d\u3046\u3067\u306a\u3044\u5834\u5408\u306fpass\u3092\u6307\u5b9a\u3057\u305f\u307b\u3046\u304c\u4fbf\u5229\u3067\u3059\u3002<br \/>\nvcc_err_unref\u306f\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u306e\u306b\u4f7f\u308f\u308c\u3066\u3044\u306a\u3044backend\u8a2d\u5b9a\u7b49\u304c\u3042\u308b\u5834\u5408\u3067\u3082\u8b66\u544a\u3060\u3051\u3067\u8d77\u52d5\u3067\u304d\u308b\u306e\u3067\u4fbf\u5229\u3067\u3059\u3002<br \/>\n\u307e\u305f\u3001\u30de\u30af\u30ed(-D)\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u306f\u5225\u30d1\u30b9\u306b\u30c6\u30b9\u30c8\u3057\u305f\u3044VCL\u3092\u7528\u610f\u3057\u305f\u6642\u306e\u305f\u3081\u3067\u3059\u3002<br \/>\n\u30de\u30af\u30ed\u306fVTC\u5185\u306e\u307f\u3067\u5229\u7528\u3067\u304d\u308b\u305f\u3081\u3001include\u3057\u305f\u5148\u306eVCL\u3067\u30de\u30af\u30ed\u5c55\u958b\u3092\u3057\u3088\u3046\u3068\u3057\u3066\u3082\u51fa\u6765\u306a\u3044\u306e\u3067\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<h4>\u30c9\u30e1\u30a4\u30f3\u30fb\u30bf\u30a4\u30d7\u8a2d\u5b9a<\/h4>\n<p><b>vtc\u30b5\u30f3\u30d7\u30eb<\/b><\/p>\n<pre><code>\nvarnish v1 -arg \"-pvcc_err_unref=off\" -vcl {\n    include \"${test_conf}\";\n} -start\nclient c_img {\n    txreq -req GET -url \"\/img\/hoge.gif\" -hdr \"Host: hogehoge.i.gree.jp\"\n    rxresp\n    expect resp.status        == \"200\"\n    expect resp.http.expires  != \"\"\n} -run\nclient c_e403_1 {\n    txreq -req GET -url \"\/hogehoge\/\" -hdr \"Host: hogehoge.i.gree.jp\"\n    rxresp\n    expect resp.status        == \"403\"\n} -run\n<\/code><\/pre>\n<p><b>\u30c6\u30b9\u30c8\u5b9f\u884c\u30b3\u30de\u30f3\u30c9<\/b><\/p>\n<pre><code>\nsudo varnishtest -Dtest_conf=\/etc\/varnish\/default.vcl *.vtc\n<\/code><\/pre>\n<p>\u3053\u306eVTC\u3067\u306f\u4ee5\u4e0b\u306e\u30c1\u30a7\u30c3\u30af\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<ul>\n<li>\/img\/hoge.gif\u306b\u30ea\u30af\u30a8\u30b9\u30c8\u3057\u3066\u30b9\u30c6\u30fc\u30bf\u30b9\u304c200<\/li>\n<li>\/hogehoge\/\u306b\u30ea\u30af\u30a8\u30b9\u30c8\u3057\u3066\u30b9\u30c6\u30fc\u30bf\u30b9\u304c403<\/li>\n<\/ul>\n<p>\u3053\u3053\u3067\u306fpass\u306e\u3088\u3046\u306b\u7121\u99c4\u306aVCL\u306f\u8a18\u8ff0\u3057\u307e\u305b\u3093\u3002<br \/>\n\u5358\u7d14\u306binclude\u3059\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<h3>\u307e\u3068\u3081<\/h3>\n<p>include\u3092\u3046\u307e\u304f\u4f7f\u3046\u3053\u3068\u3067varnishtest\u3092\u4f7f\u3046\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<br \/>\n\u7d14\u6b63\u306e\u30c4\u30fc\u30eb\u306a\u306e\u3067\u30c6\u30b9\u30c8\u304cFail\u3057\u305f\u6642\u306b\u4f55\u51e6\u304c\u5f15\u3063\u304b\u304b\u3063\u305f\u306e\u304b\u308f\u304b\u308b\u306e\u3067\u4fbf\u5229\u3060\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001\u4eca\u56de\u306fvarnish3\u5411\u3051\u306evtc\u3092\u66f8\u304d\u307e\u3057\u305f\u304cvarnish4\u3067\u3082\u307b\u307c\u307b\u307c\u540c\u3058\u3067\u3059\u3002<\/p>\n<h3>varnishtest\u306e\u304a\u307e\u3051<\/h3>\n<p>\u4ee5\u524d\u3001\u3069\u3053\u304b\u3067\u4e0e\u592a\u8a71\u3068\u3057\u3066\u8a71\u3057\u305f\u306e\u3067\u3059\u304c<br \/>\nvarnishtest\u306fvarnish\u306e\u30c6\u30b9\u30c8\u76ee\u7684\u3058\u3083\u306a\u304f\u3066\u3082\u4f7f\u3048\u307e\u3059\u3002<br \/>\n\u4f8b\u3048\u3070\u30c6\u30b9\u30c8\u3067Apache\u3092\u8d77\u52d5\u3057\u3066localhost:80\u306b\u63a5\u7d9a\u3057\u3066\u30c6\u30b9\u30c8\u3092\u884c\u3046\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><code>\nshell \"\/etc\/init.d\/apache2 start\"\nclient c_test -connect \"localhost:80\"{\n    txreq -req GET -url \"\/hogehoge.gif\" -hdr \"Host: hoge.i.gree.jp\"\n    rxresp\n    expect resp.status        == \"404\"\n    expect resp.http.expires  != \"\"\n} -run\n<\/code><\/pre>\n<p><b>\u5b9f\u884c\u30ed\u30b0<\/b><\/p>\n<pre><code>\n######## sample.vtc ########\n * Starting web server apache2\n######## sample.vtc ########\napache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName\n######## sample.vtc ########\nhttpd (pid 17466) already running\n######## sample.vtc ########\n   ...done.\n#     top  TEST sample.vtc passed (0.083)\n<\/code><\/pre>\n<p>\u3053\u306e\u3088\u3046\u306a\u4f7f\u3044\u65b9\u3082\u53ef\u80fd\u3067\u3059\u3002<br \/>\n\u308f\u3056\u308f\u3056\u4ed6\u306e\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u306e\u30c6\u30b9\u30c8\u3067varnishtest\u3092\u4f7f\u3046\u3053\u3068\u3082\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001<br \/>\n\u3061\u3087\u3063\u3068\u3057\u305f\u30c6\u30b9\u30c8\u3092\u884c\u3046\u969b\u306b\u306f\u4fbf\u5229\u3060\u3068\u601d\u3046\u306e\u3067\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<br \/>\n\u306a\u304a\u3001\u9014\u4e2d\u3067\u5f15\u3063\u304b\u304b\u3063\u305f\u5834\u5408\u306f\u4ee5\u964d\u306e\u30b9\u30c6\u30c3\u30d7\u306f\u5b9f\u884c\u3055\u308c\u306a\u3044\u306e\u3067\u3001<br \/>\n\u521d\u671f\u5316\u30fb\u7d42\u4e86\u51e6\u7406\u304c\u3042\u308b\u5834\u5408\u306f\u4f55\u304b\u3057\u3089\u306eshell\u30b9\u30af\u30ea\u30d7\u30c8\u304b\u3089\u5b9f\u884c\u3059\u308b\u306e\u3092\u304a\u3059\u3059\u3081\u3057\u307e\u3059\u3002<br \/>\n<a name=\"body\"><\/a><\/p>\n<h2>Body\u3092\u8aad\u3082\u3046\uff01<\/h2>\n<p>Varnish\u3092\u4f7f\u3063\u3066Request\/Response header\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u306f\u3088\u304f\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u69d8\u306b\u3067\u3059\u3002<br \/>\n<code><\/p>\n<pre>\nsub vcl_recv {\n  \/\/\u9759\u7684\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u30a2\u30af\u30bb\u30b9\u306e\u5834\u5408\u306f\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u30af\u30c3\u30ad\u30fc\u3092\u524a\u9664\u3059\u308b\n  if(req.url ~ \"\\.(css|js|png|jpg|gif|ico|json)(\\?.*)?$\"){\n    unset req.http.cookie;\n  }\n}\n<\/pre>\n<p><\/code><br \/>\n\u540c\u3058\u3088\u3046\u306bBody\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u305f\u3089\u975e\u5e38\u306b\u4fbf\u5229\u3060\u3068\u60f3\u50cf\u3067\u304d\u307e\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306f\u3042\u304f\u307e\u3067\u30a4\u30e1\u30fc\u30b8\u3067\u5b9f\u969b\u306b\u52d5\u4f5c\u3057\u306a\u3044\u3082\u306e\u3067\u3059\u304c\u3053\u306e\u3088\u3046\u306a\u5f62\u3067\u3067\u304d\u308b\u3068\u5b09\u3057\u304b\u3063\u305f\u308a\u3057\u307e\u3059\u3002<br \/>\n<code><\/p>\n<pre>\nsub vcl_recv {\n  \/\/POST\u30ea\u30af\u30a8\u30b9\u30c8\u4e2d\u306beval(\u3067\u59cb\u307e\u308b\u6587\u5b57\u304c\u3042\u3063\u305f\u3089400\u3067\u8fd4\u3059\n  if(req.method ~ \"POST\"){\n    if(req.body ~ \"eval\\(\"){\n      return(synth(400));\n    }\n  }\n}\n<\/pre>\n<p><\/code><br \/>\n\u3053\u306e\u3088\u3046\u306a\u4e8b\u3092\u3084\u3063\u3066\u3044\u308b\u30d7\u30ed\u30c0\u30af\u30c8\u306e\u4ee3\u8868\u4f8b\u3068\u3057\u3066\u306f<a href=\"https:\/\/github.com\/comotion\/VSF\">Varnish Security Firewall(VSF)<\/a>\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\nVSF\u3067\u306f<a href=\"https:\/\/github.com\/xcir\/libvmod-parsereq\">vmod-parsereq<\/a>\u3092Request body\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u304a\u4e16\u8f9e\u306b\u3082\u884c\u5100\u304c\u826f\u3044\u3068\u306f\u8a00\u3048\u306a\u3044\u3082\u306e\u3067\u3001\u3069\u3061\u3089\u304b\u3068\u8a00\u3046\u3068\u9ed2\u9b54\u8853\u306b\u8fd1\u3044\u3082\u306e\u3067\u3057\u305f\u3002\uff08<a href=\"https:\/\/github.com\/xcir\/libvmod-parsereq\/blob\/master\/src\/vmod_parsereq_core.c#L915\">\u53c2\u8003<\/a>\uff09<br \/>\n\u3053\u306e\u3088\u3046\u306bRequest body\u306b\u5bfe\u3057\u3066\u64cd\u4f5c\u3092\u884c\u3046\u306e\u306f\u975e\u5e38\u306b\u56f0\u96e3\u3067\u3057\u305f\u3002<br \/>\n\u307e\u305f\u540c\u69d8\u306bResponse body\u306b\u3064\u3044\u3066\u3082\u975e\u5e38\u306b\u56f0\u96e3\u3067\u3001\u672c\u4f53\u306b\u30d1\u30c3\u30c1\u3092\u9069\u7528\u3057\u306a\u3044\u3068\u30a2\u30af\u30bb\u30b9\u51fa\u6765\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n<p>\u3057\u304b\u3057VMOD\u4f5c\u8005\u304b\u3089\u306e\u8981\u671b\u304c\u5c4a\u3044\u305f\u306e\u304b4.0.x\u3067Request body\u306b\u5bfe\u3057\u3066\u624b\u8efd\u306b\u30a2\u30af\u30bb\u30b9\u51fa\u6765\u308b\u65b9\u6cd5\u304c\u63d0\u4f9b\u3055\u308c\u307e\u3057\u305f\u3002<br \/>\n\u305d\u3057\u3066\u6b21\u671f\u30d0\u30fc\u30b8\u30e7\u30f3\u306e4.1.x(\u73fe\u5728trunk)\u3067\u306fResponse body\u306b\u5bfe\u3057\u3066\u3082\u30a2\u30af\u30bb\u30b9\u51fa\u6765\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3053\u3067\u4eca\u56de\u306f4.1.x\u30d9\u30fc\u30b9\u3067\u5404body\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002<br \/>\n\u5f53\u7136\u306a\u304c\u3089<\/p>\n<ul>\n<li>\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u8a18\u8f09\u3055\u308c\u3066\u3044\u306a\u3044<\/li>\n<li>4.1\u306f\u7d76\u8cdb\u958b\u767a\u4e2d<\/li>\n<li>\u516c\u5f0f\u306b\u660e\u78ba\u306b\u8a00\u53ca\u3055\u308c\u3066\u3044\u306a\u3044(\u30d5\u30c3\u30af\u3067\u304d\u308b\u30dd\u30a4\u30f3\u30c8\u3092\u5897\u3084\u3059\u3068\u306f\u8a00\u3063\u3066\u3044\u308b\u7a0b\u5ea6)<\/li>\n<li>\u30b3\u30a2\u306b\u8fd1\u3044\u6a5f\u80fd<\/li>\n<\/ul>\n<p>\u306e\u305f\u3081\u7a81\u7136\u5909\u66f4\u3055\u308c\u308b\u53ef\u80fd\u6027\u306f\u3042\u308a\u307e\u3059\u304c\u3001\u6050\u3089\u304f4.2.x\u307e\u3067\u306f\u5909\u308f\u3063\u3066\u3082\u5c0f\u898f\u6a21\u3060\u308d\u3046\u3068\u8e0f\u3093\u3067\u3044\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u5229\u7528\u3057\u305f\u306e\u306f<a href=\"https:\/\/github.com\/varnish\/Varnish-Cache\/tree\/7f48458\">Rev.7f48458<\/a>\u3067\u3059<br \/>\nvmod\u81ea\u4f53\u306e\u4f5c\u308a\u65b9\u306b\u3064\u3044\u3066\u306f<a href=\"https:\/\/github.com\/varnish\/libvmod-example\/tree\/4.0\">libvmod-example(4.0)<\/a>\u3092\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><a name=\"vrb\"><\/a><\/p>\n<h3>Request body\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b(VRB)<\/h3>\n<p>\u307e\u305aRequest body\u306b\u30a2\u30af\u30bb\u30b9\u51fa\u6765\u308b\u3068\u4f55\u304c\u51fa\u6765\u308b\u304b\u3068\u3044\u3046\u3068<br \/>\nGET\u3060\u3051\u3067\u306a\u304fPOST\u30ea\u30af\u30a8\u30b9\u30c8\u4e2d\u306b\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u7684\u306b\u554f\u984c\u304c\u306a\u3044\u304b\u306e\u30c1\u30a7\u30c3\u30af\u304c\u53ef\u80fd\u306b\u306a\u3063\u305f\u308a<br \/>\n\u30d1\u30fc\u30b9\u3059\u308b\u3053\u3068\u3067POST\u306e\u30ad\u30fc\u3067\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u305f\u308a\u3057\u307e\u3059\u3002\uff08\u3042\u307e\u308a\u304a\u3059\u3059\u3081\u3057\u307e\u305b\u3093\u304c\uff09<br \/>\n\u4ed6\u306b\u3082\u30b5\u30fc\u30d0\u30fc\u304c503\u30a8\u30e9\u30fc\u3092\u8fd4\u3057\u305f\u6642\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u4fdd\u5b58\u3059\u308b\u3088\u3046\u306a\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u66f8\u304f\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2014\/12\/vrb1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2014\/12\/vrb1-600x213.png\" alt=\"vrb\" width=\"600\" height=\"213\" class=\"alignnone size-medium wp-image-12907\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2014\/12\/vrb1-600x213.png 600w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2014\/12\/vrb1-276x98.png 276w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2014\/12\/vrb1-830x296.png 830w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2014\/12\/vrb1.png 973w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><br \/>\n\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306e\u306f\u975e\u5e38\u306b\u7c21\u5358\u3067\u3001\u56f3\u306e\u3088\u3046\u306bVRB_Cache\u3067Request body\u3092Transient storage\u306b\u4fdd\u5b58\u3057\u3066\u305d\u308c\u3092\u8aad\u307f\u8fbc\u3080\u5f62\u3068\u306a\u308a\u307e\u3059\u3002<br \/>\nVRB_Cache\u306f\u4fbf\u5229\u306b\u30e9\u30c3\u30d7\u3055\u308c\u305fstd.cache_req_body\u304c\u3042\u308b\u306e\u3067\u4eca\u56de\u306f\u305d\u308c\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u8aad\u307f\u8fbc\u3093\u3060Response body\u3092syslog\u306b\u98db\u3070\u3059\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><b>vmod_test.vcc<\/b><br \/>\n<code><\/p>\n<pre>\n$Module test 3 test\n\n$Function VOID printRequestBody()\n<\/pre>\n<p><\/code><\/p>\n<p><b>vmod_test.c<\/b><br \/>\n<code><\/p>\n<pre>\n#include <stdio.h>\n#include <stdlib.h>\n#include <syslog.h>\n\n#include \"vrt.h\"\n#include \"cache\/cache.h\"\n#include \"cache\/cache_filter.h\"\n#include \"cache\/cache_director.h\"\n\n#include \"vcc_if.h\"\n\nstatic int __match_proto__(req_body_iter_f)\nvbf_printRequestBody(struct req *req, void *priv, void *ptr, size_t l)\n{\n    CHECK_OBJ_NOTNULL(req, REQ_MAGIC);\n    if (l > 0) {\n        syslog(6,\"dump:%d %s\",(int)l,(char*)ptr);\n    }\n    return (0);\n}\n\nVCL_VOID vmod_printRequestBody(const struct vrt_ctx *ctx){\n    VRB_Iterate(ctx->req,vbf_printRequestBody,NULL);\n}\n<\/pre>\n<p><\/code><\/p>\n<p><b>default.vcl<\/b><br \/>\n<code><\/p>\n<pre>\nvcl 4.0;\nimport std;\nimport test;\n\n\/\/backend\u306e\u8a2d\u5b9a\u3092\u66f8\u304f\n\nsub vcl_recv{\n  std.cache_req_body(1MB);\n}\nsub vcl_deliver{\n  test.printRequestBody();\n}\n\n<\/pre>\n<p><\/code><\/p>\n<p><b>request<\/b><br \/>\n<code><\/p>\n<pre>\nPOST \/ HTTP\/1.0\nContent-Length: 26\nContent-Type: text\/plain\n\nhogehogehoge.magemagemage.\n<\/pre>\n<p><\/code><br \/>\n<b>syslog<\/b><br \/>\n<code><\/p>\n<pre>\nDec  9 18:19:56 varnish4 varnishd[9504]: dump:26 hogehogehoge.magemagemage.\n<\/pre>\n<p><\/code><\/p>\n<p>\u7121\u4e8b\u3068\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002<br \/>\nvcl_recv\u3067VRB_Cache\u3092\u547c\u3073\u51fa\u305b\u3070\uff08\u4eca\u56de\u306fstd.cache_req_body\u3092\u5229\u7528\uff09<br \/>\nvcl_deliver\u3067\u3082Request body\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u308b\u306e\u3067\u3001\u5148\u307b\u3069\u306e\u4f7f\u7528\u4f8b\u306b\u3042\u3052\u305f503\u30a8\u30e9\u30fc\u6642\u306b\u4fdd\u5b58\u3059\u308b\u3053\u3068\u3082\u305d\u3053\u307e\u3067\u96e3\u3057\u304f\u3042\u308a\u307e\u305b\u3093\u3002<br \/>\n\u4f46\u3057\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u8fbc\u3082\u3046\u3068\u3059\u308b\u306e\u306f\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u52a3\u5316\u306b\u7e4b\u304c\u308b\u306e\u3067\u907f\u3051\u308b\u306e\u304c\u7121\u96e3\u3067\u3059\u3002<br \/>\n\u79c1\u3067\u3042\u308c\u3070VSL\u306b\u51fa\u529b\u3057\u3066\u5225\u306e\u30c4\u30fc\u30eb\u3067\u53d6\u5f97\u3057\u3066\u4fdd\u5b58\u3092\u884c\u3044\u307e\u3059\u3002<br \/>\nVSL\u306b\u3064\u3044\u3066\u306fV3\u5411\u3051\u3067\u3059\u304c\u3053\u3061\u3089\u306e\u8a18\u4e8b\u3092<a href=\"http:\/\/labs.gree.jp\/blog\/2013\/12\/8979\/\" title=\"Varnish\u306e\u30ed\u30b0\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u307f\u3088\u3046\uff01\">\u53c2\u7167<\/a>\u304f\u3060\u3055\u3044<\/p>\n<h3>Response body\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b<\/h3>\n<p>Response body\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u30dd\u30a4\u30f3\u30c8\u306f\uff12\u3064\u3042\u308a\u307e\u3059\u3002<br \/>\n1\u3064\u306ffetch\u6642(VFP)<br \/>\n\u3082\u30461\u3064\u306f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306b\u30ec\u30b9\u30dd\u30f3\u30b9\u3059\u308b\u76f4\u524d\u3067\u3059(VDP)<br \/>\n\u3053\u308c\u3089\u306fVarnish\u306e\u6a5f\u80fd\u306b\u3042\u308bESI\u3084gzip\/gunzip\u3067\u3082\u4f7f\u308f\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\nESI\/gzip\u3067\u4f7f\u308f\u308c\u3066\u308b\u3053\u3068\u304b\u3089\u308f\u304b\u308b\u3088\u3046\u306b\u3001\u3069\u3061\u3089\u3082\u8aad\u307f\u66f8\u304d\u304c\u53ef\u80fd\u3067\u3059\u3002<br \/>\n\u3067\u306f\u3069\u3061\u3089\u3092\u4f7f\u3048\u3070\u3088\u3044\u3067\u3057\u3087\u3046\u304b\uff1f\u305d\u308c\u305e\u308c\u306b\u306f\u6b21\u306e\u7279\u5fb4\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\nVFP\u306e\u5834\u5408\u306fFetch\u6642\u306eStorage\u306b\u5bfe\u3057\u3066\u8aad\u307f\u66f8\u304d\u3059\u308b\u305f\u30811\u56de\u306e\u307f\u547c\u3073\u51fa\u3055\u308c\u307e\u3059\u3002<br \/>\n\u305d\u306e\u305f\u3081CPU\u30b3\u30b9\u30c8\u304c\u9ad8\u3044\u51e6\u7406\u306f\u3053\u3061\u3089\u3067\u3084\u308b\u3068\u3088\u3044\u3067\u3057\u3087\u3046\u3002<br \/>\nVDP\u306e\u5834\u5408\u306fClient\u306b\u30ec\u30b9\u30dd\u30f3\u30b9\u3059\u308b\u305f\u3073\u306b\u547c\u3073\u51fa\u3055\u308c\u307e\u3059\u3002<br \/>\n\u3057\u304b\u3057\u5b9f\u969b\u306b\u30ec\u30b9\u30dd\u30f3\u30b9\u3059\u308b\u5185\u5bb9\u3092\u898b\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<br \/>\n\u4f8b\u3048\u3070\u3001ESI\u3092\u4f7f\u3063\u3066\u3044\u308b\u5834\u5408\u306fVFP\u3067\u306f\u5168\u4f53\u50cf\u306f\u308f\u304b\u308a\u307e\u305b\u3093\u304cVDP\u3060\u3068\u53ef\u80fd\u3067\u3059\u3002<br \/>\n\u307e\u305f\u3069\u3061\u3089\u3082\u6ce8\u610f\u3059\u308b\u70b9\u304c2\u70b9\u6709\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>Body\u306e\u5185\u5bb9\u306b\u3088\u3063\u3066VCL\u5185\u3067\u52d5\u4f5c\u3092\u5909\u3048\u308b\u3053\u3068\u306f\u51fa\u6765\u306a\u3044<\/li>\n<li>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306fgzip\u3067\u5727\u7e2e\u3055\u308c\u3066\u3044\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b<\/li>\n<\/ul>\n<p>VFP\/VDP\u306f\u3069\u3061\u3089\u3082\u30d5\u30a3\u30eb\u30bf\u3092\u4e8b\u524d\u306b\u767b\u9332\u3057\u3066\u304a\u304d\u3001VCL\u306eFunction\u3092\u629c\u3051\u305f\u5f8c\u306b\u547c\u3073\u51fa\u3055\u308c\u308b\u305f\u3081\u3001Body\u3092\u8aad\u307f\u8fbc\u3093\u3060\u7d50\u679c\u3067\u306e\u5224\u5b9a\u306f\u51fa\u6765\u307e\u305b\u3093\u3002\u7d14\u7c8b\u306b\u30d5\u30a3\u30eb\u30bf\u30fc\u3068\u3057\u3066\u8003\u3048\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u3082\u3061\u308d\u3093\u767b\u9332\u6642\u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u6e21\u3059\u3053\u3068\u306f\u53ef\u80fd\u3067\u3059\u3002<br \/>\n\u307e\u305fgzip\u306b\u3064\u3044\u3066\u306f\u4eca\u56de\u306fESI\u306eVFP\/VDP\u306e\u30d5\u30a3\u30eb\u30bf\u306e\u30b3\u30fc\u30c9\u3092\u8aad\u3080\u3068\u53c2\u8003\u306b\u306a\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2014\/12\/vfp-vdp1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2014\/12\/vfp-vdp1-418x400.png\" alt=\"vfp-vdp\" width=\"418\" height=\"400\" class=\"alignnone size-medium wp-image-12943\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2014\/12\/vfp-vdp1-418x400.png 418w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2014\/12\/vfp-vdp1-209x200.png 209w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2014\/12\/vfp-vdp1-830x793.png 830w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2014\/12\/vfp-vdp1.png 1194w\" sizes=\"auto, (max-width: 418px) 100vw, 418px\" \/><\/a><br \/>\n\u4e0a\u56f3\u306fVFP\/VDP\u304c\u3069\u306e\u30bf\u30a4\u30df\u30f3\u30b0\u3067Storage\u306b\u8aad\u307f\u66f8\u304d\u3092\u3057\u305f\u308a\u3001Client\u306bResponse\u3059\u308b\u304b\u3092\u793a\u3057\u305f\u3082\u306e\u3067\u3059\u3002<br \/>\n\u7740\u76ee\u3059\u308b\u3079\u304d\u306a\u306e\u306fVFP\u306e\u4e00\u756a\u4e0b\u5c64\u306e\u30d5\u30a3\u30eb\u30bf(v1f_(eof|straight|chunked))\u3067Backend\u304b\u3089Body\u3092\u8aad\u307f\u8fbc\u3093\u3067Storage\u306b\u683c\u7d0d\u3057\u3066\u3044\u308b\u3053\u3068\u3067\u3059\u3002<br \/>\nv1f_(eof|straight|chunked)\u306f\u6b21\u306e\u30d5\u30a3\u30eb\u30bf\u304c\u7121\u3044\u305f\u3081return\u3057\u3066\u3044\u304f\u305f\u3081\u3001vfp_suck\u3092\u547c\u3073\u51fa\u3057\u305f\u5f8c\u306bbody\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u307e\u3059\u3002<br \/>\n\u9006\u306bVDP\u306e\u5834\u5408\u306f\u6700\u4e0b\u5c64\u306ev1d_bytes\u3067Response\u3057\u3066\u3044\u308b\u305f\u3081\u3001VDP_Bytes\u3092\u547c\u3073\u51fa\u3059\u524d\u306bbody\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u305d\u308c\u3067\u306f\u5b9f\u969b\u306bVFP\/VDP\u3092\u4f7f\u3063\u3066Response body\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<h4>Response body\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b(Fetch\/VFP)<\/h4>\n<p><b>vmod_test.vcc<\/b><br \/>\n<code><\/p>\n<pre>\n$Module test 3 test\n\n$Function VOID HookFetch()\n<\/pre>\n<p><\/code><\/p>\n<p><b>vmod_test.c<\/b><br \/>\n<code><\/p>\n<pre>\n#include <stdio.h>\n#include <stdlib.h>\n#include <syslog.h>\n\n#include \"vrt.h\"\n#include \"cache\/cache.h\"\n#include \"cache\/cache_filter.h\"\n#include \"cache\/cache_director.h\"\n\n#include \"vcc_if.h\"\n\nstatic enum vfp_status __match_proto__(vfp_pull_f)\nvmod_vfp_pull_f(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p, ssize_t *lp){\n    enum vfp_status vp;\n    vp = VFP_Suck(vc, p, lp);\n    syslog(6,\"VFP  %s\",(const char*)p);\n    return (vp);\n}\n\nstatic enum vfp_status __match_proto__(vfp_init_f)\nvfp_pull_init(struct vfp_ctx *vc, struct vfp_entry *vfe)\n{\n    syslog(6,\"init\");\n    return (VFP_OK);\n}\n\nstatic void __match_proto__(vfp_fini_f)\nvfp_pull_fini(struct vfp_ctx *vc, struct vfp_entry *vfe)\n{\n    syslog(6,\"fini\");\n}\n\nconst struct vfp vfp_PREF = {\n    .name = \"TEST\",\n    .init = vfp_pull_init,\n    .pull = vmod_vfp_pull_f,\n    .fini = vfp_pull_fini,\n};\n\nVCL_VOID vmod_HookFetch(const struct vrt_ctx *ctx){\n    (void)VFP_Push(ctx->bo->vfc,&vfp_PREF,1);\n\n}\n<\/pre>\n<p><\/code><\/p>\n<p><b>default.vcl<\/b><br \/>\n<code><\/p>\n<pre>\nvcl 4.0;\nimport std;\nimport test;\n\n\/\/backend\u306e\u8a2d\u5b9a\u3092\u66f8\u304f\n\nsub vcl_backend_response{\n  test.HookFetch();\n}\n\n<\/pre>\n<p><\/code><\/p>\n<p><b>request<\/b><br \/>\nPOST\u3067\u3042\u308b\u5fc5\u8981\u306f\u306a\u3044\u306e\u3067\u666e\u901a\u306b\u30ea\u30af\u30a8\u30b9\u30c8\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><b>syslog<\/b><br \/>\n<code><\/p>\n<pre>\nDec 10 19:50:28 varnish4 varnishd[9459]: init\nDec 10 19:50:28 varnish4 varnishd[9459]: VFP  <html><body><h1>It works!<\/h1>#012This is the default web page for this server.<\/p>#012<p>The web server software is running but no content has been added, yet.<\/p>#012<\/body><\/html>#012\nDec 10 19:50:28 varnish4 varnishd[9459]: fini\n<\/pre>\n<p><\/code><br \/>\n\u4f55\u5ea6\u304b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\nVFP\u304c\u547c\u3070\u308c\u308b\u306e\u306f\u4e00\u5ea6\u3060\u3051\u3060\u3068\u3044\u3046\u3053\u3068\u304c\u308f\u304b\u308b\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u4f55\u304b\u3057\u3089\u306e\u521d\u671f\u5316\u51e6\u7406\u304c\u5fc5\u8981\u306a\u5834\u5408\u306f.init\u3067\u5b9a\u7fa9\u3057\u305ffunction\u306b\u7d42\u4e86\u51e6\u7406\u304c\u5fc5\u8981\u306a\u5834\u5408\u306f.fini\u3092\u4f7f\u3046\u3068\u53ef\u80fd\u3067\u3059\u3002<br \/>\n\u5148\u307b\u3069\u3082\u8aac\u660e\u3057\u305f\u3068\u304a\u308a\u3001Body\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u306e\u306fVFP_Suck\u3092\u547c\u3073\u51fa\u3057\u305f\u5f8c\u306a\u306e\u3067\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<h4>Response body\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b(Deliver\/VDP)<\/h4>\n<p><b>vmod_test.vcc<\/b><br \/>\n<code><\/p>\n<pre>\n$Module test 3 test\n\n$Function VOID HookDeliv()\n<\/pre>\n<p><\/code><\/p>\n<p><b>vmod_test.c<\/b><br \/>\n<code><\/p>\n<pre>\n#include <stdio.h>\n#include <stdlib.h>\n#include <syslog.h>\n\n#include \"vrt.h\"\n#include \"cache\/cache.h\"\n#include \"cache\/cache_filter.h\"\n#include \"cache\/cache_director.h\"\n\n#include \"vcc_if.h\"\n\nint __match_proto__(vdp_bytes)\nVDP_test(struct req *req, enum vdp_action act, void **priv,\n    const void *ptr, ssize_t len)\n{\n    if (act == VDP_INIT || act == VDP_FINI)\n        return (0);\n    syslog(6,\"resp.body(len=%zd) %s \",len,(char*)ptr);\n    return(VDP_bytes(req, act, ptr, len));\n\n}\nVCL_VOID vmod_HookDeliv(const struct vrt_ctx *ctx){\n    VDP_push(ctx->req, VDP_test, NULL, 0);\n}\n\n\n<\/pre>\n<p><\/code><\/p>\n<p><b>default.vcl<\/b><br \/>\n<code><\/p>\n<pre>\nvcl 4.0;\nimport std;\nimport test;\n\n\/\/backend\u306e\u8a2d\u5b9a\u3092\u66f8\u304f\n\nsub vcl_deliver{\n  test.HookDeliv();\n}\n\n<\/pre>\n<p><\/code><\/p>\n<p><b>request<\/b><br \/>\nPOST\u3067\u3042\u308b\u5fc5\u8981\u306f\u306a\u3044\u306e\u3067\u666e\u901a\u306b\u30ea\u30af\u30a8\u30b9\u30c8\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><b>syslog<\/b><br \/>\n<code><\/p>\n<pre>\nDec 10 20:02:29 varnish4 varnishd[10487]: resp.body(len=177) <html><body><h1>It works!<\/h1>#012This is the default web page for this server.<\/p>#012<p>The web server software is running but no content has been added, yet.<\/p>#012<\/body><\/html>#012\n<\/pre>\n<p><\/code><br \/>\n\u4f55\u5ea6\u304b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\nVFP\u3068\u9055\u3044\u6bce\u56de\u547c\u3073\u51fa\u3055\u308c\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002<br \/>\n\u4f55\u304b\u3057\u3089\u306e\u521d\u671f\u5316\/\u7d42\u4e86\u51e6\u7406\u304c\u5fc5\u8981\u306a\u5834\u5408\u306fact\u304cVDP_INIT|VDP_FINI\u306e\u3068\u304d\u306b\u51e6\u7406\u3067\u304d\u307e\u3059\u3002<br \/>\nVFP\u3068\u9055\u3044Function\u306f\u5206\u304b\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u500b\u4eba\u7684\u306b\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u308b\u307e\u3067\u306b\u5909\u66f4\u304c\u3042\u308b\u5834\u5408\u306f\u3053\u3053\u304cVFP\u306e\u3088\u3046\u306b\u5909\u66f4\u3055\u308c\u308b\u306e\u3067\u306f\uff1f\u3068\u8003\u3048\u3066\u3044\u307e\u3059\u3002<br \/>\n\u307e\u305f\u5148\u307b\u3069\u3082\u8aac\u660e\u3057\u305f\u3068\u304a\u308a\u3001Body\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u306e\u306fVDP_Bytes\u306e\u547c\u51fa\u3057\u524d\u306a\u306e\u3067\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<h3>\u307e\u3068\u3081<\/h3>\n<p>Varnish4.1(\u4e88\u5b9a)\u3067\u306f\u6bd4\u8f03\u7684\u7c21\u5358\u306bRequest\/Response body\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3057\u305f\u3002<br \/>\n\u3053\u308c\u3092\u4f7f\u3048\u3070HTML\u30d8\u30c3\u30c0\u4e2d\u306bjs\u3092\u633f\u5165\u3057\u305f\u308a\u3001\u81ea\u52d5\u7684\u306b\u753b\u50cf\u7b49\u306eURL\u306e\u96e3\u8aad\u5316\u3084\u30b7\u30e7\u30fc\u30c8\u30bf\u30a4\u30e0\u30c8\u30fc\u30af\u30f3\u306e\u4ed8\u4e0e\u306a\u3069\u304c\u51fa\u6765\u305f\u308a\u3057\u307e\u3059\u3002<br \/>\n\u307e\u305f\u3053\u308c\u306f\u79c1\u306e\u5984\u60f3\u3067\u3059\u304c\u3001VFP\u3067\u4ed6\u306e\u30ea\u30bd\u30fc\u30b9\u3092prefetch\u3057\u3066VDP\u3067HTTP\/2\u306epush\u3067\u304d\u305f\u3089\u9762\u767d\u3044\u3088\u306a\u30fc\u3068\u304b\u8003\u3048\u3066\u3044\u307e\u3059\u3002<br \/>\nprefetch\u306f\u4eca\u3082\u5b9f\u88c5\u306f\u3067\u304d\u308b\u306e\u3067\u3059\u304c\u30d1\u30e9\u30ec\u30eb\u5316\u304c\u9ed2\u9b54\u8853\u306b\u306a\u308a\u305d\u3046\u3060\u3063\u305f\u306e\u3067\u3001\u30d1\u30e9\u30ec\u30ebESI\u304c\u6765\u308b\u307e\u3067\u307e\u3068\u3046\u3068\u8003\u3048\u3066\u3044\u307e\u3059\u3002<br \/>\n\u4ed6\u306b\u3082\u4f7f\u3044\u65b9\u306f\u3044\u308d\u3044\u308d\u3042\u308b\u3068\u601d\u3046\u306e\u3067\u305c\u3072\u30c1\u30e3\u30ec\u30f3\u30b8\u3057\u3066\u307f\u308b\u3068\u9762\u767d\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u3042\u3068\u672c\u65e512\/17\u306f\u79c1\u306e\u8a95\u751f\u65e5\u3060\u3063\u305f\u308a\u3057\u307e\u3059\uff01<a href=\"http:\/\/www.amazon.co.jp\/registry\/wishlist\/AEP24O7PTXM8\/ref=cm_sw_r_tw_ws_ky9Qsb0DD15F1\">\u30d7\u30ec\u30bc\u30f3\u30c8\u304a\u5f85\u3061\u3057\u3066\u304a\u308a\u307e\u3059\uff01<\/a><\/p>\n<p>\u660e\u65e5\u306f@hosi_mo\uff08\u8a95\u751f\u65e5\uff09\u3055\u3093\u306b\u3088\u308b\u30cd\u30a4\u30c6\u30a3\u30d6\u30b2\u30fc\u30e0\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306e\u8a2d\u8a08\u306b\u3064\u3044\u3066\u306e\u8a18\u4e8b\u3067\u3059\u3002\u304a\u697d\u3057\u307f\u306b\uff01<\/p>\n<h3>\u53c2\u8003\u8cc7\u6599<\/h3>\n<p><a href=\"https:\/\/www.varnish-cache.org\/trac\/wiki\/VDD14Q2\">VDD14Q2<\/a><br \/>\n<a href=\"https:\/\/www.varnish-cache.org\/trac\/wiki\/VDD14Q4\">VDD14Q4<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001Service Reliability\u30c1\u30fc\u30e0\u306e\u3044\u308f\u306a\u3061\u3083\u3093\u3055\u3093(@xcir)\u3067\u3059\u3002 \u5148\u65e5\u3001\u793e\u5185\u3067\u884c\u308f\u308c\u305f\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u30cf\u30c3\u30ab\u30bd\u30f3\u3067\u306f\u30c1\u30fc\u30e0\u30de\u30a4\u30ca\u30b95500\u4e07\u3068\u3057\u3066Varnish\u3092\u3044\u308c\u308b\u7c21\u5358\u306a\u304a\u4ed5\u4e8b\u3092\u3057\u3066\u304d\u307e\u3057\u305f [&hellip;]<\/p>\n","protected":false},"author":136,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[54,52],"class_list":["post-10734","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-advent-calendar","tag-varnish-cache"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/10734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/users\/136"}],"replies":[{"embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/comments?post=10734"}],"version-history":[{"count":3,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/10734\/revisions"}],"predecessor-version":[{"id":15344,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/10734\/revisions\/15344"}],"wp:attachment":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/media?parent=10734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/categories?post=10734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/tags?post=10734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}