Authentication
● Basic認証を行うモジュール
ID/PWを固定で簡単に認証を入れたい時は便利
● Developed by Omega Software Development Group
● https://github.com/omegasdg/libvmod-authentication
サンプルコード
import authentication;
vcl_recv{
if(req.url ~ "^/protected/") {
if(!authentication.match("admin", "test")) {
error 401 "Authentication Required";
}
}
}
vcl_error{
if (obj.status == 401) {
set obj.http.WWW-Authenticate = {"Basic realm="Authorization Required""};
synthetic {"Error 401 Unauthorized"};
return(deliver);
}
}
14.
crashhandler
● セグフォを起こしてバックトレースを取得する
VMODやインラインCでのデバッグに使う
● Developed by Kristian Lyngstøl
● https://github.com/varnish/libvmod-crashhandler
サンプルコード
import crashhandler;
vcl_recv{
if(req.url ~ "^/crash/") {
crashhandler.crash();
}
}
15.
cURL
● VCL中にHTTPで他リソースを取得する
APIを叩いてその結果のような使い方ができるかも
● Developed by Varnish Software
● https://github.com/varnish/libvmod-curl
サンプルコード
import curl;
sub vcl_recv {
curl.fetch("http://example.com/test");
if (curl.header("X-Foo") == "bar") {
… }
curl.free();
}
16.
dClass OpenDDR
(decision classification)
● UAからデバイス情報を取得する(OpenDDR)
ぱっと見た感じディスプレイサイズなども取得可能
● Developed by Weather Channel
● https://github.com/TheWeatherChannel/dClass
サンプルコード
import dclass;
sub vcl_init {
dclass.init_dclass("/some/path/OpenDDR/1.0.0.0/resources");
dclass.init_dclass_p("/some/path/dClass/dtrees/browser.dtree",1);
}
sub vcl_recv {
set req.http.dclass_openddr = dclass.classify(req.http.user-agent);
set req.http.dclass_browser = dclass.classify_p(req.http.user-agent,1);
if(dclass.get_ifield("displayWidth") > 320){
....
}
}
17.
DeviceAtlas Mobile Detection
● モバイルデバイスの各種情報を取得
● Developed by Varnish Software
● Varnishソフトウェアが有償で提供しています
● https://www.varnish-cache.org/vmod/deviceatlas-mobile-detection
18.
Digest
● HMAC-sha1などダイジェストやBase64が扱える
SHA1などのDigestの出力はHEXエンコードされて
いるので注意
● Developed by Kristian Lyngstøl
● https://github.com/varnish/libvmod-digest
サンプルコード
import digest;
sub vcl_recv {
if (digest.hmac_sha256("key",req.http.x-some-header) !=
digest.hmac_sha256("key",req.http.x-some-header-signed))
{
error 401 "Naughty user!";
}
}
19.
example vmod -hello world!
● VMODを作るときに参考になります
● Developed by Martin Blix Grydeland
● https://github.com/varnish/libvmod-example
サンプルコード
import example;
sub vcl_deliver {
# This sets resp.http.hello to "Hello, World"
set resp.http.hello = example.hello("World");
}
20.
Header manipulation
● ヘッダーの操作を行うモジュール
主にクッキーの値の追加や削除を行う
● Developed by Kristian Lyngstøl
● https://github.com/varnish/libvmod-header
サンプルコード
import header;
sub vcl_fetch {
header.append(beresp.http.Set-Cookie,"foo=bar");
header.remove(beresp.http.Set-Cookie,"dontneedthiscookie");
}
21.
Memcached
● Memcacheへ値のset/get/incrなどを行う
● Developed by Aaron Stone
● https://github.com/sodabrew/libvmod-memcached
サンプルコード
import memcached;
sub vcl_deliver {
memcached.servers("localhost");
memcached.set("your_counter", "1", 100, 0);
memcached.incr("your_counter", 10);
set resp.http.count = memcached.incr("your_counter", 1);
}
22.
null - Binarydata in synthetic
● バイナリデータを送信したいときに利用
vcl_errorでインラインCから使うのが一般的
● Developed by Kristian Lyngstøl
● https://github.com/varnish/libvmod-header
サンプルコード
import null;
sub vcl_error {
C{
Vmod_Func_null.synth(sp,"TEST",4);
}C
return(deliver);
}