Guest User

Untitled

a guest
Jul 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. +init_comp_types_table() ->
  2. + ets:new(?COMP_TYPES_TABLE, [named_table, set, protected]),
  3. + case ?MODULE:get("httpd", "compressable_types_list_file") of
  4. + undefined ->
  5. + ok;
  6. + FileName ->
  7. + {ok, F} = file:open(FileName, read),
  8. + load_compressable_types(F),
  9. + file:close(F)
  10. + end,
  11. + ok.
  12. +
  13. +load_compressable_types(F) ->
  14. + {ok, LineRe} = re:compile("^\\s*(.*?)\\s*$"),
  15. + {ok, MimeRe} = re:compile("^(.*?)\\s*(?:;\\s*(.*?)\\s*)?$"),
  16. + NextLine = fun() -> io:get_line(F, '') end,
  17. + ParseLines = fun(eof, _Cont, _GetNextLine) ->
  18. + ok;
  19. + (Line, Cont, GetNextLine) ->
  20. + case re:run(Line, LineRe, [{capture, [1], list}]) of
  21. + {match, [Line1]} ->
  22. + case Line1 of
  23. + [] ->
  24. + ok; % blank line
  25. + [$# | _] ->
  26. + ok; % comment line
  27. + _ ->
  28. + case re:run(Line1, MimeRe, [{capture, [1,2], list}]) of
  29. + {match, [Type, _Params]} ->
  30. + ets:insert(
  31. + ?COMP_TYPES_TABLE,
  32. + {string:to_lower(Type), true}
  33. + );
  34. + _ ->
  35. + ok
  36. + end
  37. + end;
  38. + _ ->
  39. + ok
  40. + end,
  41. + Cont(GetNextLine(), Cont, GetNextLine)
  42. + end,
  43. + ParseLines(NextLine(), ParseLines, NextLine).
Add Comment
Please, Sign In to add comment