forked from erlyaws/yaws
-
Notifications
You must be signed in to change notification settings - Fork 0
How to filter requests in traces
capflam edited this page Sep 15, 2011
·
1 revision
The trace filter can be set by calling yaws_trace:set_filter(Filter). This function parse Filter argument and create a function representing the filter. It returns true if the request matches the filter.
If tracing is enabled and the filter is evaluated to true, trace messages are logged.
To unset or retreive this filter, you can call, respectively, yaws_trace:unset_filter() and yaws_trace:get_filter().
Here is the filter structure:
Filter ::= {'and', [Filter]} | {'and', Filter, Filter} |
{'or', [Filter]} | {'or', Filter, Filter} |
{'not', Filter} |
{'equal', Elmt, Value} |
{'startby', Elmt, Value} |
{'endwith', Elmt, Value} |
{'contain', Elmt, Value} |
{'match', Elmt, Re}.
Elmt ::= 'ip' | {'request', ReqElmt} | {'header', HdrElmt}.
Value ::= string().
Re ::= string().
ReqElmt ::= 'method' | 'path' | 'version'.
HdrElmt ::= 'connection' | 'accept' | 'host' | 'if_modified_since' |
'if_match' | 'if_none_match' | 'if_range' | 'if_unmodified_since' |
'range' | 'referer' | 'user_agent' | 'accept_ranges' |
'cookie' | 'location' | 'content_length' | 'content_type' |
'content_encoding' | 'authorization' | 'transfer_encoding' | 'x_forwarded_for' |
atom() | string().
Some elements are stringified:
- The HTTP version follows the format
HTTP/{Maj}.{Min}(Ex: HTTP/1.0) - The cookie is flattened
- Authorization follows the format
{User}:{Pass}:{Orig}.{User}and{Pass}can be empty
- Filter requests coming from 127.0.0.1 on all gif images:
1> yaws_trace:set_filter({'and', {'equal', 'ip', "127.0.0.1"}, {'match', {'request', 'path'}, "^.*\.gif$"}}). ok
- Filter requests from GoogleBot:
2> yaws_trace:set_filter({'contain', {'header', 'user_agent'}, "Googlebot/2.1"}). ok
- Exclude requests from GoogleBot:
3> yaws_trace:set_filter({'not', {contain, {'header', 'user_agent'}, "Googlebot/2.1"}}). ok
- Filter ‘POST’ requests with the header ‘X-Trusted’, for all IPs but 127.0.0.1:
4> yaws_trace:set_filter({'and', [ {'equal', {'request', 'method'}, "POST"}, {'startby', {'header', "X-Trusted"}, ""}, {'not', {'equal', 'ip', "127.0.0.1"}} ]}). ok