http.hrl 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_cookies() :: list({binary(), binary()}).
  16. -type http_status() :: non_neg_integer() | binary().
  17. -type http_resp_body() :: iodata() | {non_neg_integer(),
  18. fun(() -> {sent, non_neg_integer()})}.
  19. -record(http_req, {
  20. %% Transport.
  21. socket = undefined :: undefined | inet:socket(),
  22. transport = undefined :: undefined | module(),
  23. connection = keepalive :: keepalive | close,
  24. %% Request.
  25. pid = undefined :: pid(),
  26. method = 'GET' :: cowboy_http:method(),
  27. version = {1, 1} :: cowboy_http:version(),
  28. peer = undefined :: undefined | {inet:ip_address(), inet:ip_port()},
  29. host = undefined :: undefined | cowboy_dispatcher:tokens(),
  30. host_info = undefined :: undefined | cowboy_dispatcher:tokens(),
  31. raw_host = undefined :: undefined | binary(),
  32. port = undefined :: undefined | inet:ip_port(),
  33. path = undefined :: undefined | '*' | cowboy_dispatcher:tokens(),
  34. path_info = undefined :: undefined | cowboy_dispatcher:tokens(),
  35. raw_path = undefined :: undefined | binary(),
  36. qs_vals = undefined :: undefined | list({binary(), binary() | true}),
  37. raw_qs = undefined :: undefined | binary(),
  38. bindings = undefined :: undefined | cowboy_dispatcher:bindings(),
  39. headers = [] :: cowboy_http:headers(),
  40. p_headers = [] :: [any()], %% @todo Improve those specs.
  41. cookies = undefined :: undefined | http_cookies(),
  42. meta = [] :: [{atom(), any()}],
  43. %% Request body.
  44. body_state = waiting :: waiting | done |
  45. {multipart, non_neg_integer(), fun()},
  46. buffer = <<>> :: binary(),
  47. %% Response.
  48. resp_state = waiting :: locked | waiting | chunks | done,
  49. resp_headers = [] :: cowboy_http:headers(),
  50. resp_body = <<>> :: http_resp_body(),
  51. %% Functions.
  52. urldecode :: {fun((binary(), T) -> binary()), T}
  53. }).