Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- +init_comp_types_table() ->
- + ets:new(?COMP_TYPES_TABLE, [named_table, set, protected]),
- + case ?MODULE:get("httpd", "compressable_types_list_file") of
- + undefined ->
- + ok;
- + FileName ->
- + {ok, F} = file:open(FileName, read),
- + load_compressable_types(F),
- + file:close(F)
- + end,
- + ok.
- +
- +load_compressable_types(F) ->
- + {ok, LineRe} = re:compile("^\\s*(.*?)\\s*$"),
- + {ok, MimeRe} = re:compile("^(.*?)\\s*(?:;\\s*(.*?)\\s*)?$"),
- + NextLine = fun() -> io:get_line(F, '') end,
- + ParseLines = fun(eof, _Cont, _GetNextLine) ->
- + ok;
- + (Line, Cont, GetNextLine) ->
- + case re:run(Line, LineRe, [{capture, [1], list}]) of
- + {match, [Line1]} ->
- + case Line1 of
- + [] ->
- + ok; % blank line
- + [$# | _] ->
- + ok; % comment line
- + _ ->
- + case re:run(Line1, MimeRe, [{capture, [1,2], list}]) of
- + {match, [Type, _Params]} ->
- + ets:insert(
- + ?COMP_TYPES_TABLE,
- + {string:to_lower(Type), true}
- + );
- + _ ->
- + ok
- + end
- + end;
- + _ ->
- + ok
- + end,
- + Cont(GetNextLine(), Cont, GetNextLine)
- + end,
- + ParseLines(NextLine(), ParseLines, NextLine).
Add Comment
Please, Sign In to add comment