http.hrl 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. %% Copyright (c) 2011, Loïc Hoguin <essen@dev-extend.eu>
  2. %% Copyright (c) 2011, Anthony Ramine <nox@dev-extend.eu>
  3. %%
  4. %% Permission to use, copy, modify, and/or distribute this software for any
  5. %% purpose with or without fee is hereby granted, provided that the above
  6. %% copyright notice and this permission notice appear in all copies.
  7. %%
  8. %% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. %% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. %% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. %% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. %% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. %% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. %% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. -type http_status() :: non_neg_integer() | binary().
  16. -type http_resp_body() :: iodata() | {non_neg_integer(),
  17. fun(() -> {sent, non_neg_integer()})}.
  18. -record(http_req, {
  19. %% Transport.
  20. socket = undefined :: undefined | inet:socket(),
  21. transport = undefined :: undefined | module(),
  22. connection = keepalive :: keepalive | close,
  23. %% Request.
  24. pid = undefined :: pid(),
  25. method = 'GET' :: cowboy_http:method(),
  26. version = {1, 1} :: cowboy_http:version(),
  27. peer = undefined :: undefined | {inet:ip_address(), inet:ip_port()},
  28. host = undefined :: undefined | cowboy_dispatcher:tokens(),
  29. host_info = undefined :: undefined | cowboy_dispatcher:tokens(),
  30. raw_host = undefined :: undefined | binary(),
  31. port = undefined :: undefined | inet:ip_port(),
  32. path = undefined :: undefined | '*' | cowboy_dispatcher:tokens(),
  33. path_info = undefined :: undefined | cowboy_dispatcher:tokens(),
  34. raw_path = undefined :: undefined | binary(),
  35. qs_vals = undefined :: undefined | list({binary(), binary() | true}),
  36. raw_qs = undefined :: undefined | binary(),
  37. bindings = undefined :: undefined | cowboy_dispatcher:bindings(),
  38. headers = [] :: cowboy_http:headers(),
  39. p_headers = [] :: [any()], %% @todo Improve those specs.
  40. cookies = undefined :: undefined | [{binary(), binary()}],
  41. meta = [] :: [{atom(), any()}],
  42. %% Request body.
  43. body_state = waiting :: waiting | done |
  44. {multipart, non_neg_integer(), fun()},
  45. buffer = <<>> :: binary(),
  46. %% Response.
  47. resp_state = waiting :: locked | waiting | chunks | done,
  48. resp_headers = [] :: cowboy_http:headers(),
  49. resp_body = <<>> :: http_resp_body(),
  50. %% Functions.
  51. urldecode :: {fun((binary(), T) -> binary()), T}
  52. }).