Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

105 строки
2.8 KiB

3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
  1. -include_lib("eNet/include/eNet.hrl").
  2. %% @type version(). HTTP version as a tuple, i.e. `{0, 9} | {1, 0} | {1, 1}'.
  3. -type version() :: {0, 9} | {1, 0} | {1, 1}.
  4. -export_type([version/0]).
  5. -define(DefWsOpts, [
  6. binary
  7. , {packet, 4}
  8. , {active, false}
  9. , {reuseaddr, true}
  10. , {nodelay, false}
  11. , {delay_send, true}
  12. , {send_timeout, 15000}
  13. , {keepalive, true}
  14. , {exit_on_close, true}
  15. , {back_log, 1024}
  16. ]).
  17. -export_type([wsOpt/0]).
  18. -type wsOpt() ::
  19. listenOpt() |
  20. {wsMod, module()}.
  21. -record(wsReq, {
  22. method :: method(),
  23. scheme :: undefined | binary(),
  24. host :: undefined | binary(),
  25. port :: undefined | 1..65535,
  26. path :: [binary()],
  27. args :: [{binary(), any()}],
  28. raw_path :: binary(),
  29. version :: wsHttp:version(),
  30. headers :: headers(),
  31. original_headers :: headers(),
  32. body :: body(),
  33. pid :: pid()
  34. }).
  35. -export_type([req/0, method/0, body/0, headers/0, response_code/0]).
  36. %% @type req(). A record representing an HTTP request.
  37. -type req() :: #wsReq{}.
  38. %% @type http_method(). An uppercase atom representing a known HTTP verb or a
  39. %% binary for other verbs.
  40. -type method() :: 'OPTIONS' | 'GET' | 'HEAD' | 'POST'| 'PUT' | 'DELETE' | 'TRACE' | binary().
  41. %% @type body(). A binary or iolist.
  42. -type body() :: binary() | iolist().
  43. -type header() :: {Key :: binary(), Value :: binary() | string()}.
  44. -type headers() :: [header()].
  45. -type response_code() :: 100..999.
  46. -define(EXAMPLE_CONF, [{callback, elli_example_callback}, {callback_args, []}]).
  47. -define(CONTENT_LENGTH_HEADER, <<"content-length">>).
  48. -define(EXPECT_HEADER, <<"expect">>).
  49. -define(CONNECTION_HEADER, <<"connection">>).
  50. -define(TRANSFER_ENCODING_HEADER, <<"Transfer-Encoding">>).
  51. -export_type([callback/0, callback_mod/0, callback_args/0, event/0, result/0]).
  52. %% @type callback(). A tuple of a {@type callback_mod()} and {@type
  53. %% callback_args()}.
  54. -type callback() :: {callback_mod(), callback_args()}.
  55. %% @type callback_mod(). A callback module.
  56. -type callback_mod() :: module().
  57. %% @type callback_args(). Arguments to pass to a {@type callback_mod()}.
  58. -type callback_args() :: list().
  59. %% @type event(). Fired throughout processing a request.
  60. %% See {@link elli_example_callback:handle_event/3} for descriptions.
  61. -type event() ::
  62. elli_startup|
  63. bad_request |
  64. file_error|
  65. chunk_complete |
  66. request_complete|
  67. request_throw |
  68. request_error |
  69. request_exit|
  70. request_closed |
  71. request_parse_error|
  72. client_closed |
  73. client_timeout|
  74. invalid_return.
  75. -type result() ::
  76. {elli:response_code() |ok, elli:headers(), {file, file:name_all()}|
  77. {file, file:name_all(), wsUtil:range()}}|
  78. {elli:response_code() | ok, elli:headers(), elli:body()}|
  79. {elli:response_code() | ok, elli:body()}|
  80. {chunk, elli:headers()}|
  81. {chunk, elli:headers(), elli:body()}|
  82. ignore.
  83. -type sendfile_opts() :: [{chunk_size, non_neg_integer()}].