http.hrl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_method() :: 'OPTIONS' | 'GET' | 'HEAD'
  16. | 'POST' | 'PUT' | 'DELETE' | 'TRACE' | binary().
  17. -type http_uri() :: '*' | {absoluteURI, http | https, Host::binary(),
  18. Port::integer() | undefined, Path::binary()}
  19. | {scheme, Scheme::binary(), binary()}
  20. | {abs_path, binary()} | binary().
  21. -type http_version() :: {Major::non_neg_integer(), Minor::non_neg_integer()}.
  22. -type http_header() :: 'Cache-Control' | 'Connection' | 'Date' | 'Pragma'
  23. | 'Transfer-Encoding' | 'Upgrade' | 'Via' | 'Accept' | 'Accept-Charset'
  24. | 'Accept-Encoding' | 'Accept-Language' | 'Authorization' | 'From' | 'Host'
  25. | 'If-Modified-Since' | 'If-Match' | 'If-None-Match' | 'If-Range'
  26. | 'If-Unmodified-Since' | 'Max-Forwards' | 'Proxy-Authorization' | 'Range'
  27. | 'Referer' | 'User-Agent' | 'Age' | 'Location' | 'Proxy-Authenticate'
  28. | 'Public' | 'Retry-After' | 'Server' | 'Vary' | 'Warning'
  29. | 'Www-Authenticate' | 'Allow' | 'Content-Base' | 'Content-Encoding'
  30. | 'Content-Language' | 'Content-Length' | 'Content-Location'
  31. | 'Content-Md5' | 'Content-Range' | 'Content-Type' | 'Etag'
  32. | 'Expires' | 'Last-Modified' | 'Accept-Ranges' | 'Set-Cookie'
  33. | 'Set-Cookie2' | 'X-Forwarded-For' | 'Cookie' | 'Keep-Alive'
  34. | 'Proxy-Connection' | binary().
  35. -type http_headers() :: list({http_header(), binary()}).
  36. %% -type http_cookies() :: term(). %% @todo
  37. -type http_status() :: non_neg_integer() | binary().
  38. -record(http_req, {
  39. %% Transport.
  40. socket = undefined :: undefined | inet:socket(),
  41. transport = undefined :: undefined | module(),
  42. connection = keepalive :: keepalive | close,
  43. %% Request.
  44. method = 'GET' :: http_method(),
  45. version = {1, 1} :: http_version(),
  46. peer = undefined :: undefined | {inet:ip_address(), inet:ip_port()},
  47. host = undefined :: undefined | cowboy_dispatcher:path_tokens(),
  48. host_info = undefined :: undefined | cowboy_dispatcher:path_tokens(),
  49. raw_host = undefined :: undefined | binary(),
  50. port = undefined :: undefined | inet:ip_port(),
  51. path = undefined :: undefined | '*' | cowboy_dispatcher:path_tokens(),
  52. path_info = undefined :: undefined | cowboy_dispatcher:path_tokens(),
  53. raw_path = undefined :: undefined | binary(),
  54. qs_vals = undefined :: undefined | list({binary(), binary() | true}),
  55. raw_qs = undefined :: undefined | binary(),
  56. bindings = undefined :: undefined | cowboy_dispatcher:bindings(),
  57. headers = [] :: http_headers(),
  58. %% cookies = undefined :: undefined | http_cookies() %% @todo
  59. %% Request body.
  60. body_state = waiting :: waiting | done,
  61. buffer = <<>> :: binary(),
  62. %% Response.
  63. resp_state = locked :: locked | waiting | chunks | done
  64. }).