Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 63 lines (51 sloc) 1.669 kB
c650d77 @capflam add shaper directive to control access (capflam)
capflam authored
1 %%%----------------------------------------------------------------------
2 %%% File : yaws_shaper.erl
3 %%% Author : Christopher Faulet <christopher@yakaz.com>
4 %%% Purpose :
5 %%% Created : 14 Dec 2010 by Christopher Faulet <christopher@yakaz.com>
6 %%%----------------------------------------------------------------------
7
8 -module(yaws_shaper).
9 -author('christopher@yakaz.com').
10
11
12 -export([behaviour_info/1]).
13
14 %% API
15 -export([
16 check/2,
17 update/3
18 ]).
19
20
21 -include("../include/yaws.hrl").
22 -include("../include/yaws_api.hrl").
23 -include("yaws_debug.hrl").
24
25
26 %%%----------------------------------------------------------------------
27 %%% API
28 %%%----------------------------------------------------------------------
29 behaviour_info(callbacks) ->
30 [{check,1}, {update,3}];
31 behaviour_info(_Other) ->
32 undefined.
33
34
35 check(#sconf{shaper=undefined}, _) ->
36 allow;
37 check(#sconf{shaper=Mod}, IP) ->
38 case catch Mod:check(IP) of
39 allow ->
40 allow;
41 {deny, Status, Msg} ->
42 {deny, Status, Msg};
43 _ ->
44 allow
45 end.
46
47 update(#sconf{shaper=undefined}, _, _) ->
48 ok;
49 update(#sconf{shaper=Mod}, IP, Req) ->
50 Bytes = case Req#http_request.method of
51 'HEAD' -> 0;
52 _ ->
53 case yaws:outh_get_contlen() of
54 undefined ->
55 case yaws:outh_get_act_contlen() of
56 undefined -> 0;
57 Actlen -> Actlen
58 end;
59 I2 -> I2
60 end
61 end,
62 catch Mod:update(IP, 1, Bytes).
Something went wrong with that request. Please try again.