http.hrl 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_version() :: {Major::non_neg_integer(), Minor::non_neg_integer()}.
  16. -type http_header() :: 'Cache-Control' | 'Connection' | 'Date' | 'Pragma'
  17. | 'Transfer-Encoding' | 'Upgrade' | 'Via' | 'Accept' | 'Accept-Charset'
  18. | 'Accept-Encoding' | 'Accept-Language' | 'Authorization' | 'From' | 'Host'
  19. | 'If-Modified-Since' | 'If-Match' | 'If-None-Match' | 'If-Range'
  20. | 'If-Unmodified-Since' | 'Max-Forwards' | 'Proxy-Authorization' | 'Range'
  21. | 'Referer' | 'User-Agent' | 'Age' | 'Location' | 'Proxy-Authenticate'
  22. | 'Public' | 'Retry-After' | 'Server' | 'Vary' | 'Warning'
  23. | 'Www-Authenticate' | 'Allow' | 'Content-Base' | 'Content-Encoding'
  24. | 'Content-Language' | 'Content-Length' | 'Content-Location'
  25. | 'Content-Md5' | 'Content-Range' | 'Content-Type' | 'Etag'
  26. | 'Expires' | 'Last-Modified' | 'Accept-Ranges' | 'Set-Cookie'
  27. | 'Set-Cookie2' | 'X-Forwarded-For' | 'Cookie' | 'Keep-Alive'
  28. | 'Proxy-Connection' | binary().
  29. -type http_headers() :: list({http_header(), iodata()}).
  30. -type http_cookies() :: list({binary(), binary()}).
  31. -type http_status() :: non_neg_integer() | binary().
  32. -type http_resp_body() :: iodata() | {non_neg_integer(),
  33. fun(() -> {sent, non_neg_integer()})}.
  34. -record(http_req, {
  35. %% Transport.
  36. socket = undefined :: undefined | inet:socket(),
  37. transport = undefined :: undefined | module(),
  38. connection = keepalive :: keepalive | close,
  39. %% Request.
  40. pid = undefined :: pid(),
  41. method = 'GET' :: cowboy_http:method(),
  42. version = {1, 1} :: http_version(),
  43. peer = undefined :: undefined | {inet:ip_address(), inet:ip_port()},
  44. host = undefined :: undefined | cowboy_dispatcher:tokens(),
  45. host_info = undefined :: undefined | cowboy_dispatcher:tokens(),
  46. raw_host = undefined :: undefined | binary(),
  47. port = undefined :: undefined | inet:ip_port(),
  48. path = undefined :: undefined | '*' | cowboy_dispatcher:tokens(),
  49. path_info = undefined :: undefined | cowboy_dispatcher:tokens(),
  50. raw_path = undefined :: undefined | binary(),
  51. qs_vals = undefined :: undefined | list({binary(), binary() | true}),
  52. raw_qs = undefined :: undefined | binary(),
  53. bindings = undefined :: undefined | cowboy_dispatcher:bindings(),
  54. headers = [] :: http_headers(),
  55. p_headers = [] :: [any()], %% @todo Improve those specs.
  56. cookies = undefined :: undefined | http_cookies(),
  57. meta = [] :: [{atom(), any()}],
  58. %% Request body.
  59. body_state = waiting :: waiting | done |
  60. {multipart, non_neg_integer(), fun()},
  61. buffer = <<>> :: binary(),
  62. %% Response.
  63. resp_state = waiting :: locked | waiting | chunks | done,
  64. resp_headers = [] :: http_headers(),
  65. resp_body = <<>> :: http_resp_body(),
  66. %% Functions.
  67. urldecode :: {fun((binary(), T) -> binary()), T}
  68. }).