http.hrl 2.5 KB

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