http.hrl 3.5 KB

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