Created
January 13, 2013 10:39
-
-
Save dvv/4523495 to your computer and use it in GitHub Desktop.
A draft of user agent determination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -spec user_agent_platform(binary()) -> undefined | atom(). | |
| user_agent_platform(Header) -> | |
| user_agent(cowboy_bstr:to_lower(Header), [ | |
| {<<"windows">>, windows}, | |
| {<<"linux">>, linux}, | |
| {<<"os x ">>, osx}, | |
| {<<"android">>, android}, | |
| {<<"ipod">>, ipod}, | |
| {<<"iphone">>, iphone}, | |
| {<<"ipad">>, ipad} | |
| ]). | |
| -spec user_agent(binary()) -> undefined | atom(). | |
| user_agent(Header) -> | |
| user_agent(cowboy_bstr:to_lower(Header), [ | |
| {<<"msie">>, ie}, | |
| {<<"chrome">>, chrome}, | |
| {<<"firefox">>, firefox}, | |
| {<<"opera">>, opera}, | |
| {<<"safari">>, safari}, | |
| {<<"konqueror">>, konqueror}, | |
| {<<"curl">>, curl} | |
| ]). | |
| user_agent(_Header, []) -> | |
| undefined; | |
| user_agent(Header, [{Pattern, UA} | Rest]) -> | |
| case binary:match(Header, Pattern) of | |
| nomatch -> user_agent(Header, Rest); | |
| _ -> UA | |
| end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment