http.hrl 3.8 KB

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