http.hrl 3.5 KB

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