Browse files

basic method to not allow new requests, but needs to deal with messag…

…es already in mailbox...
  • Loading branch information...
1 parent e1f9a26 commit 33cb8aa11d5626f82cedf13ef12ca85dbe98424c @tsloughter committed Jul 11, 2012
Showing with 6 additions and 14,002 deletions.
  1. +1 −4 config/sys.config
  2. +0 −10 deps/cowboy-0.6.0/.gitignore
  3. +0 −18 deps/cowboy-0.6.0/AUTHORS
  4. +0 −299 deps/cowboy-0.6.0/CHANGELOG.md
  5. +0 −13 deps/cowboy-0.6.0/LICENSE
  6. +0 −59 deps/cowboy-0.6.0/Makefile
  7. +0 −290 deps/cowboy-0.6.0/README.md
  8. +0 −101 deps/cowboy-0.6.0/ROADMAP.md
  9. +0 −1 deps/cowboy-0.6.0/cover.spec
  10. +0 −4 deps/cowboy-0.6.0/doc/overview.edoc
  11. 0 deps/cowboy-0.6.0/ebin/.gitignore
  12. +0 −16 deps/cowboy-0.6.0/ebin/cowboy.app
  13. BIN deps/cowboy-0.6.0/ebin/cowboy.beam
  14. BIN deps/cowboy-0.6.0/ebin/cowboy_acceptor.beam
  15. BIN deps/cowboy-0.6.0/ebin/cowboy_acceptors_sup.beam
  16. BIN deps/cowboy-0.6.0/ebin/cowboy_app.beam
  17. BIN deps/cowboy-0.6.0/ebin/cowboy_bstr.beam
  18. BIN deps/cowboy-0.6.0/ebin/cowboy_client.beam
  19. BIN deps/cowboy-0.6.0/ebin/cowboy_clock.beam
  20. BIN deps/cowboy-0.6.0/ebin/cowboy_cookies.beam
  21. BIN deps/cowboy-0.6.0/ebin/cowboy_dispatcher.beam
  22. BIN deps/cowboy-0.6.0/ebin/cowboy_http.beam
  23. BIN deps/cowboy-0.6.0/ebin/cowboy_http_handler.beam
  24. BIN deps/cowboy-0.6.0/ebin/cowboy_http_protocol.beam
  25. BIN deps/cowboy-0.6.0/ebin/cowboy_http_req.beam
  26. BIN deps/cowboy-0.6.0/ebin/cowboy_http_rest.beam
  27. BIN deps/cowboy-0.6.0/ebin/cowboy_http_static.beam
  28. BIN deps/cowboy-0.6.0/ebin/cowboy_http_websocket.beam
  29. BIN deps/cowboy-0.6.0/ebin/cowboy_http_websocket_handler.beam
  30. BIN deps/cowboy-0.6.0/ebin/cowboy_listener.beam
  31. BIN deps/cowboy-0.6.0/ebin/cowboy_listener_sup.beam
  32. BIN deps/cowboy-0.6.0/ebin/cowboy_multipart.beam
  33. BIN deps/cowboy-0.6.0/ebin/cowboy_protocol.beam
  34. BIN deps/cowboy-0.6.0/ebin/cowboy_requests_sup.beam
  35. BIN deps/cowboy-0.6.0/ebin/cowboy_ssl_transport.beam
  36. BIN deps/cowboy-0.6.0/ebin/cowboy_sup.beam
  37. BIN deps/cowboy-0.6.0/ebin/cowboy_tcp_transport.beam
  38. +0 −6 deps/cowboy-0.6.0/examples/README.md
  39. +0 −58 deps/cowboy-0.6.0/include/http.hrl
  40. +0 −6 deps/cowboy-0.6.0/rebar.config
  41. +0 −7 deps/cowboy-0.6.0/rebar.tests.config
  42. +0 −26 deps/cowboy-0.6.0/src/cowboy.app.src
  43. +0 −114 deps/cowboy-0.6.0/src/cowboy.erl
  44. +0 −57 deps/cowboy-0.6.0/src/cowboy_acceptor.erl
  45. +0 −48 deps/cowboy-0.6.0/src/cowboy_acceptors_sup.erl
  46. +0 −53 deps/cowboy-0.6.0/src/cowboy_app.erl
  47. +0 −86 deps/cowboy-0.6.0/src/cowboy_bstr.erl
  48. +0 −315 deps/cowboy-0.6.0/src/cowboy_client.erl
  49. +0 −254 deps/cowboy-0.6.0/src/cowboy_clock.erl
  50. +0 −408 deps/cowboy-0.6.0/src/cowboy_cookies.erl
  51. +0 −311 deps/cowboy-0.6.0/src/cowboy_dispatcher.erl
  52. +0 −1,104 deps/cowboy-0.6.0/src/cowboy_http.erl
  53. +0 −48 deps/cowboy-0.6.0/src/cowboy_http_handler.erl
  54. +0 −508 deps/cowboy-0.6.0/src/cowboy_http_protocol.erl
  55. +0 −981 deps/cowboy-0.6.0/src/cowboy_http_req.erl
  56. +0 −919 deps/cowboy-0.6.0/src/cowboy_http_rest.erl
  57. +0 −517 deps/cowboy-0.6.0/src/cowboy_http_static.erl
  58. +0 −606 deps/cowboy-0.6.0/src/cowboy_http_websocket.erl
  59. +0 −60 deps/cowboy-0.6.0/src/cowboy_http_websocket_handler.erl
  60. +0 −224 deps/cowboy-0.6.0/src/cowboy_listener.erl
  61. +0 −46 deps/cowboy-0.6.0/src/cowboy_listener_sup.erl
  62. +0 −251 deps/cowboy-0.6.0/src/cowboy_multipart.erl
  63. +0 −61 deps/cowboy-0.6.0/src/cowboy_protocol.erl
  64. +0 −44 deps/cowboy-0.6.0/src/cowboy_requests_sup.erl
  65. +0 −177 deps/cowboy-0.6.0/src/cowboy_ssl_transport.erl
  66. +0 −42 deps/cowboy-0.6.0/src/cowboy_sup.erl
  67. +0 −119 deps/cowboy-0.6.0/src/cowboy_tcp_transport.erl
  68. +0 −97 deps/cowboy-0.6.0/test/autobahn_SUITE.erl
  69. +0 −76 deps/cowboy-0.6.0/test/autobahn_SUITE_data/test.py
  70. +0 −17 deps/cowboy-0.6.0/test/chunked_handler.erl
  71. +0 −68 deps/cowboy-0.6.0/test/dispatcher_prop.erl
  72. +0 −890 deps/cowboy-0.6.0/test/http_SUITE.erl
  73. +0 −14 deps/cowboy-0.6.0/test/http_SUITE_data/cert.pem
  74. +0 −18 deps/cowboy-0.6.0/test/http_SUITE_data/key.pem
  75. +0 −19 deps/cowboy-0.6.0/test/http_handler.erl
  76. +0 −19 deps/cowboy-0.6.0/test/http_handler_echo_body.erl
  77. +0 −40 deps/cowboy-0.6.0/test/http_handler_errors.erl
  78. +0 −17 deps/cowboy-0.6.0/test/http_handler_init_shutdown.erl
  79. +0 −22 deps/cowboy-0.6.0/test/http_handler_long_polling.erl
  80. +0 −15 deps/cowboy-0.6.0/test/http_handler_loop_timeout.erl
  81. +0 −29 deps/cowboy-0.6.0/test/http_handler_multipart.erl
  82. +0 −33 deps/cowboy-0.6.0/test/http_handler_set_resp.erl
  83. +0 −24 deps/cowboy-0.6.0/test/http_handler_stream_body.erl
  84. +0 −37 deps/cowboy-0.6.0/test/proper_SUITE.erl
  85. +0 −40 deps/cowboy-0.6.0/test/rest_forbidden_resource.erl
  86. +0 −17 deps/cowboy-0.6.0/test/rest_nodelete_resource.erl
  87. +0 −30 deps/cowboy-0.6.0/test/rest_resource_etags.erl
  88. +0 −12 deps/cowboy-0.6.0/test/rest_simple_resource.erl
  89. +0 −34 deps/cowboy-0.6.0/test/websocket_echo_handler.erl
  90. +0 −38 deps/cowboy-0.6.0/test/websocket_handler.erl
  91. +0 −30 deps/cowboy-0.6.0/test/websocket_handler_init_shutdown.erl
  92. +0 −375 deps/cowboy-0.6.0/test/ws_SUITE.erl
  93. +0 −29 deps/cowboy-0.6.0/test/ws_timeout_hibernate_handler.erl
  94. +0 −102 deps/gproc-0.2.13/doc/README.md
  95. +0 −4 deps/gproc-0.2.13/doc/edoc-info
  96. BIN deps/gproc-0.2.13/doc/erlang.png
  97. BIN deps/gproc-0.2.13/doc/erlang07-wiger.pdf
  98. +0 −1,343 deps/gproc-0.2.13/doc/gproc.md
  99. +0 −40 deps/gproc-0.2.13/doc/gproc_app.md
  100. +0 −82 deps/gproc-0.2.13/doc/gproc_bcast.md
  101. +0 −288 deps/gproc-0.2.13/doc/gproc_dist.md
  102. +0 −28 deps/gproc-0.2.13/doc/gproc_info.md
  103. +0 −37 deps/gproc-0.2.13/doc/gproc_init.md
  104. +0 −167 deps/gproc-0.2.13/doc/gproc_lib.md
  105. +0 −78 deps/gproc-0.2.13/doc/gproc_monitor.md
  106. +0 −362 deps/gproc-0.2.13/doc/gproc_ps.md
  107. +0 −33 deps/gproc-0.2.13/doc/gproc_sup.md
  108. +0 −73 deps/gproc-0.2.13/doc/overview.edoc
  109. +0 −55 deps/gproc-0.2.13/doc/stylesheet.css
  110. +0 −10 deps/gproc-0.2.13/ebin/gproc.app
  111. BIN deps/gproc-0.2.13/ebin/gproc.beam
  112. BIN deps/gproc-0.2.13/ebin/gproc_app.beam
  113. BIN deps/gproc-0.2.13/ebin/gproc_bcast.beam
  114. BIN deps/gproc-0.2.13/ebin/gproc_dist.beam
  115. BIN deps/gproc-0.2.13/ebin/gproc_info.beam
  116. BIN deps/gproc-0.2.13/ebin/gproc_init.beam
  117. BIN deps/gproc-0.2.13/ebin/gproc_lib.beam
  118. BIN deps/gproc-0.2.13/ebin/gproc_monitor.beam
  119. BIN deps/gproc-0.2.13/ebin/gproc_ps.beam
  120. BIN deps/gproc-0.2.13/ebin/gproc_sup.beam
  121. +0 −43 deps/gproc-0.2.13/include/gproc.hrl
  122. +0 −1 deps/gproc-0.2.13/priv/sys.config
  123. +0 −472 deps/ibrowse-3.0.3/doc/ibrowse.html
  124. +0 −67 deps/ibrowse-3.0.3/doc/ibrowse_lib.html
  125. +0 −1 deps/ibrowse-3.0.3/doc/short-desc
  126. +0 −9 deps/ibrowse-3.0.3/ebin/ibrowse.app
  127. BIN deps/ibrowse-3.0.3/ebin/ibrowse.beam
  128. BIN deps/ibrowse-3.0.3/ebin/ibrowse_app.beam
  129. BIN deps/ibrowse-3.0.3/ebin/ibrowse_http_client.beam
  130. BIN deps/ibrowse-3.0.3/ebin/ibrowse_lb.beam
  131. BIN deps/ibrowse-3.0.3/ebin/ibrowse_lib.beam
  132. BIN deps/ibrowse-3.0.3/ebin/ibrowse_sup.beam
  133. BIN deps/ibrowse-3.0.3/ebin/ibrowse_test.beam
  134. +0 −21 deps/ibrowse-3.0.3/include/ibrowse.hrl
  135. +0 −18 deps/ibrowse-3.0.3/priv/ibrowse.conf
  136. +0 −50 deps/proper-1.0/doc/overview.edoc
  137. +0 −1 deps/proper-1.0/ebin/.gitignore
  138. +0 −12 deps/proper-1.0/ebin/proper.app
  139. BIN deps/proper-1.0/ebin/proper.beam
  140. BIN deps/proper-1.0/ebin/proper_arith.beam
  141. BIN deps/proper-1.0/ebin/proper_array.beam
  142. BIN deps/proper-1.0/ebin/proper_dict.beam
  143. BIN deps/proper-1.0/ebin/proper_fsm.beam
  144. BIN deps/proper-1.0/ebin/proper_gb_sets.beam
  145. BIN deps/proper-1.0/ebin/proper_gb_trees.beam
  146. BIN deps/proper-1.0/ebin/proper_gen.beam
  147. BIN deps/proper-1.0/ebin/proper_orddict.beam
  148. BIN deps/proper-1.0/ebin/proper_ordsets.beam
  149. BIN deps/proper-1.0/ebin/proper_prop_remover.beam
  150. BIN deps/proper-1.0/ebin/proper_queue.beam
  151. BIN deps/proper-1.0/ebin/proper_sets.beam
  152. BIN deps/proper-1.0/ebin/proper_shrink.beam
  153. BIN deps/proper-1.0/ebin/proper_statem.beam
  154. BIN deps/proper-1.0/ebin/proper_symb.beam
  155. BIN deps/proper-1.0/ebin/proper_transformer.beam
  156. BIN deps/proper-1.0/ebin/proper_types.beam
  157. BIN deps/proper-1.0/ebin/proper_typeserver.beam
  158. BIN deps/proper-1.0/ebin/strip_types.beam
  159. BIN deps/proper-1.0/ebin/vararg.beam
  160. 0 deps/proper-1.0/include/compile_flags.hrl
  161. +0 −105 deps/proper-1.0/include/proper.hrl
  162. +0 −55 deps/proper-1.0/include/proper_common.hrl
  163. +0 −92 deps/proper-1.0/include/proper_internal.hrl
  164. +0 −41 deps/proper-1.0/include/proper_param_adts.hrl
  165. +5 −1 lib/dwight_core/src/dwight_core_req_server.erl
View
5 config/sys.config
@@ -2,9 +2,6 @@
%%% Warning - this config file *must* end with <dot><whitespace>
[ {dwight_routes, [{domains, [{<<"localhost">>, <<"abc">>},
- {<<"lenin">>, <<"efg">>},
{<<"herokudemo">>, <<"hij">>}]},
- {route_ids, [{<<"abc">>, <<"localhost">>, 7999},
- {<<"abc">>, <<"google.com">>, 80},
- {<<"efg">>, <<"google.com">>, 80},
+ {route_ids, [{<<"abc">>, <<"dwight-keepalive.herokuapp.com">>, 80},
{<<"hij">>, <<"localhost">>, 80}]}]} ].
View
10 deps/cowboy-0.6.0/.gitignore
@@ -1,10 +0,0 @@
-.cowboy.plt
-.eunit
-deps
-doc/*.css
-doc/*.html
-doc/*.png
-doc/edoc-info
-ebin
-logs
-test/*.beam
View
18 deps/cowboy-0.6.0/AUTHORS
@@ -1,18 +0,0 @@
-Cowboy is available thanks to the work of:
-
-Loïc Hoguin
-Anthony Ramine
-Magnus Klaar
-Paul Oliver
-Steven Gravell
-Tom Burdick
-Hunter Morris
-Yurii Rashkovskii
-Ali Sabil
-Hans Ulrich Niedermann
-Jesper Louis Andersen
-Mathieu Lecarme
-Max Lapshin
-Michiel Hakvoort
-Ori Bar
-Alisdair Sullivan
View
299 deps/cowboy-0.6.0/CHANGELOG.md
@@ -1,299 +0,0 @@
-CHANGELOG
-=========
-
-0.6.0
------
-
-* Add multipart support
-
-* Add chunked transfer decoding support
-
- Done by reworking the body reading API. Now all the body
- reading goes through the cowboy_http_req:stream_body/1
- function. This function takes care of handling both the
- Transfer-Encoding and the Content-Encoding, returning
- properly decoded data ready for consumption.
-
-* Add fragmented websocket messages support
-
- Properly tested by the addition of the Autobahn websocket
- test suite to our toolbox. All tests pass except a few
- related to UTF-8 handling, as Cowboy does no checks on that
- end at this point.
-
-* Add 'onrequest' and 'onresponse' hooks
-
- The first can be used for all the special cases you may have
- that can't be dealt with otherwise. It's also pretty good for
- writing access logs or rewriting URLs.
-
- The second can be used for logging errors or replacing error
- pages, amongst others.
-
-* Add cowboy:get_protocol_options/1 and cowboy:set_protocol_options/2
-
- These functions allow for retrieving a listener's protocol options,
- and for modifying them while the listener is running. This is
- most useful to upgrade the dispatch list. The upgrade applies
- to all the future connections.
-
-* Add the sockname/1 function to TCP and SSL transports
-
-* Improve SSL transport support
-
- Add support for specifying the ciphers. Add CA support. Make
- specifying the password optional.
-
-* Add new HTTP status codes from RFC 6585
-
-* Add a 'file' option to cowboy_http_static
-
- This allows for mapping /folder/ paths to a /folder/index.html file.
-
-* Add the '*' catch all Content-Type for REST
-
-* Add {halt, Req, State} as a possible return value for REST
-
-* Add absolute URI support for requests
-
-* Add cowboy_http:x_www_form_urlencoded/2
-
-* Various REST bug fixes
-
-* Do not send chunked replies for HTTP/1.0 connections
-
-* Fix a DST bug in the cookies code
-
-* Fix a bug with setting cookie values containing slashes
-
-* Fix a small timer leak when using loop/websocket timeouts
-
-* Make charset and media type parsing more relaxed
-
- This is to accomodate some widely used broken clients.
-
-* Make error messages more readable
-
-* Fix and improve type specifications
-
-* Fix a bug preventing documentation from being generated
-
-* Small improvements to the documentation
-
-* Rework the HTTP test suite
-
- The suite now uses an integrated Cowboy HTTP client. The client
- is currently experimental and shouldn't be used.
-
-* Add many many tests.
-
-0.4.0
------
-
-* Set the cowboy_listener process priority to high
-
- As it is the central process used by all incoming requests
- we need to set its priority to high to avoid timeouts that
- would happen otherwise when reaching a huge number of
- concurrent requests.
-
-* Add cowboy:child_spec/6 for embedding in other applications
-
-* Add cowboy_http_rest, an experimental REST protocol support
-
- Based on the Webmachine diagram and documentation. It is a
- new implementation, not a port, therefore a few changes have
- been made. However all the callback names are the same and
- should behave similarly to Webmachine.
-
- There is currently no documentation other than the Webmachine
- resource documentation and the comments found in cowboy_http_rest,
- which itself should be fairly easy to read and understand.
-
-* Add cowboy_http_static, an experimental static file handler
-
- Makes use of the aforementioned REST protocol support to
- deliver files with proper content type and cache headers.
-
- Note that this uses the new file:sendfile support when
- appropriate, which currently requires the VM to be started
- with the +A option defined, else errors may randomly appear.
-
-* Add cowboy_bstr module for binary strings related functions
-
-* Add cowboy_http module for HTTP parsing functions
-
- This module so far contains various functions for HTTP header
- parsing along with URL encoding and decoding.
-
-* Remove quoted from the default dependencies
-
- This should make Cowboy much easier to compile and use by default.
- It is of course still possible to use quoted as your URL decoding
- library in Cowboy thanks to the newly added urldecode option.
-
-* Fix supervisor spec for non dynamic modules to allow upgrades to complete
-
-* Add cowboy:accept_ack/1 for a cleaner handling of the shoot message
-
- Before, when the listener accepted a connection, the newly created
- process was waiting for a message containing the atom 'shoot' before
- proceeding. This has been replaced by the cowboy:accept_ack/1 function.
-
- This function should be used where 'shoot' was received because the
- contents of the message have changed (and could change again in the
- distant future).
-
-* Update binary parsing expressions to avoid hype crashes
-
- More specifically, /bits was replaced by /binary.
-
-* Rename the type cowboy_dispatcher:path_tokens/0 to tokens/0
-
-* Remove the cowboy_clock:date/0, time/0 and datetime/0 types
-
- The calendar module exports those same types properly since R14B04.
-
-* Add cacertfile configuration option to cowboy_ssl_transport
-
-* Add cowboy_protocol behaviour
-
-* Remove -Wbehaviours dialyzer option unavailable in R15B
-
-* Many tests and specs improvements
-
-### cowboy_http_req
-
-* Fix a crash when reading the request body
-
-* Add parse_header/2 and parse_header/3
-
- The following headers can now be semantically parsed: Connection, Accept,
- Accept-Charset, Accept-Encoding, Accept-Language, Content-Length,
- Content-Type, If-Match, If-None-Match, If-Modified-Since,
- If-Unmodified-Since, Upgrade
-
-* Add set_resp_header/3, set_resp_cookie/4 and set_resp_body/2
-
- These functions allow handlers to set response headers and body
- without having to reply directly.
-
-* Add set_resp_body_fun/3
-
- This function allows handlers to stream the body of the response
- using the given fun. The size of the response must be known beforehand.
-
-* Add transport/1 to obtain the transport and socket for the request
-
- This allows handlers to have low-level socket access in those cases
- where they do need it, like when streaming a response body with
- set_resp_body_fun/3.
-
-* Add peer_addr/1
-
- This function tries to guess the real peer IP based on the HTTP
- headers received.
-
-* Add meta/2 and meta/3 to save useful protocol information
-
- Currently used to save the Websocket protocol version currently used,
- and to save request information in the REST protocol handler.
-
-* Add reply/2 and reply/3 aliases to reply/4
-
-* Add upgrade_reply/3 for protocol upgrades
-
-### cowboy_http_protocol
-
-* Add the {urldecode, fun urldecode/2} option
-
- Added when quoted was removed from the default build. Can be used to
- tell Cowboy to use quoted or any other URL decoding routine.
-
-* Add the max_keepalive option
-
-* Add the max_line_length option
-
-* Allow HTTP handlers to stop during init/3
-
- To do so they can return {shutdown, Req, State}.
-
-* Add loops support in HTTP handlers for proper long-polling support
-
- A loop can be entered by returning either of {loop, Req, State},
- {loop, Req, State, hibernate}, {loop, Req, State, Timeout} or
- {loop, Req, State, Timeout, hibernate} from init/3.
-
- Loops are useful when we cannot reply immediately and instead
- are waiting for an Erlang message to be able to complete the request,
- as would typically be done for long-polling.
-
- Loop support in the protocol means that timeouts and hibernating
- are well tested and handled so you can use those options without
- worrying. It is recommended to set the timeout option.
-
- When a loop is started, handle/2 will never be called so it does
- not need to be defined. When the request process receives an Erlang
- message, it will call the info/3 function with the message as the
- first argument.
-
- Like in OTP, you do need to set timeout and hibernate again when
- returning from info/3 to enable them until the next call.
-
-* Fix the sending of 500 errors when handlers crash
-
- Now we send an error response when no response has been sent,
- and do nothing more than close the connection if anything
- did get sent.
-
-* Fix a crash when the server is sent HTTP responses
-
-* Fix HTTP timeouts handling when the Request-Line wasn't received
-
-* Fix the handling of the max number of empty lines between requests
-
-* Fix the handling of HEAD requests
-
-* Fix HTTP/1.0 Host header handling
-
-* Reply status 400 if we receive an unexpected value or error for headers
-
-* Properly close when the application sends "Connection: close" header
-
-* Close HTTP connections on all errors
-
-* Improve the error message for HTTP handlers
-
-### cowboy_http_websocket
-
-* Add websocket support for all versions up to RFC 6455
-
- Support isn't perfect yet according to the specifications, but
- is working against all currently known client implementations.
-
-* Allow websocket_init/3 to return with the hibernate option set
-
-* Add {shutdown, Req} return value to websocket_init/3 to fail an upgrade
-
-* Fix websocket timeout handling
-
-* Fix error messages: wrong callback name was reported on error
-
-* Fix byte-by-byte websocket handling
-
-* Fix an issue when using hixie-76 with certain proxies
-
-* Fix a crash in the hixie-76 handshake
-
-* Fix the handshake when SSL is used on port 443
-
-* Fix a crash in the handshake when cowboy_http_req:compact/1 is used
-
-* Fix handshake when a query string is present
-
-* Fix a crash when the Upgrade header contains more than one token
-
-0.2.0
------
-
-* Initial release.
View
13 deps/cowboy-0.6.0/LICENSE
@@ -1,13 +0,0 @@
-Copyright (c) 2011-2012, Loïc Hoguin <essen@ninenines.eu>
-
-Permission to use, copy, modify, and/or distribute this software for any
-purpose with or without fee is hereby granted, provided that the above
-copyright notice and this permission notice appear in all copies.
-
-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
View
59 deps/cowboy-0.6.0/Makefile
@@ -1,59 +0,0 @@
-# See LICENSE for licensing information.
-
-PROJECT = cowboy
-
-DIALYZER = dialyzer
-REBAR = rebar
-
-all: app
-
-# Application.
-
-deps:
- @$(REBAR) get-deps
-
-app: deps
- @$(REBAR) compile
-
-clean:
- @$(REBAR) clean
- rm -f test/*.beam
- rm -f erl_crash.dump
-
-docs: clean-docs
- @$(REBAR) doc skip_deps=true
-
-clean-docs:
- rm -f doc/*.css
- rm -f doc/*.html
- rm -f doc/*.png
- rm -f doc/edoc-info
-
-# Tests.
-
-deps/proper:
- @$(REBAR) -C rebar.tests.config get-deps
- cd deps/proper && $(REBAR) compile
-
-tests: clean deps/proper app eunit ct
-
-inttests: clean deps/proper app eunit intct
-
-eunit:
- @$(REBAR) -C rebar.tests.config eunit skip_deps=true
-
-ct:
- @$(REBAR) -C rebar.tests.config ct skip_deps=true suites=http,proper,ws
-
-intct:
- @$(REBAR) -C rebar.tests.config ct skip_deps=true suites=http,proper,ws,autobahn
-
-# Dialyzer.
-
-build-plt:
- @$(DIALYZER) --build_plt --output_plt .$(PROJECT).plt \
- --apps kernel stdlib sasl inets crypto public_key ssl
-
-dialyze:
- @$(DIALYZER) --src src --plt .$(PROJECT).plt --no_native \
- -Werror_handling -Wrace_conditions -Wunmatched_returns # -Wunderspecs
View
290 deps/cowboy-0.6.0/README.md
@@ -1,290 +0,0 @@
-Cowboy
-======
-
-Cowboy is a small, fast and modular HTTP server written in Erlang.
-
-Cowboy is also a socket acceptor pool, able to accept connections
-for any kind of TCP protocol.
-
-Goals
------
-
-Cowboy aims to provide the following advantages:
-
-* **Small** code base.
-* Damn **fast**.
-* **Modular**: transport and protocol handlers are replaceable.
-* **Binary HTTP** for greater speed and lower memory usage.
-* Easy to **embed** inside another application.
-* Selectively **dispatch** requests to handlers, allowing you to send some
- requests to your embedded code and others to a FastCGI application in
- PHP or Ruby.
-* No parameterized module. No process dictionary. **Clean** Erlang code.
-
-The server is currently in early development. Comments and suggestions are
-more than welcome. To contribute, either open bug reports, or fork the project
-and send us pull requests with new or improved functionality. You should
-discuss your plans with us before doing any serious work, though, to avoid
-duplicating efforts.
-
-Quick start
------------
-
-* Add Cowboy as a rebar or agner dependency to your application.
-* Start Cowboy and add one or more listeners.
-* Write handlers for your application.
-* Check out [examples](https://github.com/extend/cowboy_examples)!
-
-Getting Started
----------------
-
-At heart, Cowboy is nothing more than an TCP acceptor pool. All it does is
-accept connections received on a given port and using a given transport,
-like TCP or SSL, and forward them to a request handler for the given
-protocol. Acceptors and request handlers are of course supervised
-automatically.
-
-It just so happens that Cowboy also includes an HTTP protocol handler.
-But Cowboy does nothing by default. You need to explicitly ask Cowboy
-to listen on a port with your chosen transport and protocol handlers.
-To do so, you must start a listener.
-
-A listener is a special kind of supervisor that manages both the
-acceptor pool and the request processes. It is named and can thus be
-started and stopped at will.
-
-An acceptor pool is a pool of processes whose only role is to accept
-new connections. It's good practice to have many of these processes
-as they are very cheap and allow much quicker response when you get
-many connections. Of course, as with everything else, you should
-**benchmark** before you decide what's best for you.
-
-Cowboy includes a TCP transport handler for HTTP and an SSL transport
-handler for HTTPS. The transport handlers can of course be reused for
-other protocols like FTP or IRC.
-
-The HTTP protocol requires one last thing to continue: dispatching rules.
-Don't worry about it right now though and continue reading, it'll all
-be explained.
-
-You can start and stop listeners by calling `cowboy:start_listener/6` and
-`cowboy:stop_listener/1` respectively.
-
-The following example demonstrates the startup of a very simple listener.
-
-``` erlang
-application:start(cowboy),
-Dispatch = [
- %% {Host, list({Path, Handler, Opts})}
- {'_', [{'_', my_handler, []}]}
-],
-%% Name, NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts
-cowboy:start_listener(my_http_listener, 100,
- cowboy_tcp_transport, [{port, 8080}],
- cowboy_http_protocol, [{dispatch, Dispatch}]
-).
-```
-
-This is not enough though, you must also write the my_handler module
-to process the incoming HTTP requests. Of course Cowboy comes with
-predefined handlers for specific tasks but most of the time you'll
-want to write your own handlers for your application.
-
-Following is an example of a "Hello World!" HTTP handler.
-
-``` erlang
--module(my_handler).
--export([init/3, handle/2, terminate/2]).
-
-init({tcp, http}, Req, Opts) ->
- {ok, Req, undefined_state}.
-
-handle(Req, State) ->
- {ok, Req2} = cowboy_http_req:reply(200, [], <<"Hello World!">>, Req),
- {ok, Req2, State}.
-
-terminate(Req, State) ->
- ok.
-```
-
-You can also write handlers that do not reply directly. Instead, such handlers
-will wait for an Erlang message from another process and only reply when
-receiving such message, or timeout if it didn't arrive in time.
-
-This is especially useful for long-polling functionality, as Cowboy will handle
-process hibernation and timeouts properly, preventing mistakes if you were to
-write the code yourself. An handler of that kind can be defined like this:
-
-``` erlang
--module(my_loop_handler).
--export([init/3, info/3, terminate/2]).
-
--define(TIMEOUT, 60000).
-
-init({tcp, http}, Req, Opts) ->
- {loop, Req, undefined_state, ?TIMEOUT, hibernate}.
-
-info({reply, Body}, Req, State) ->
- {ok, Req2} = cowboy_http_req:reply(200, [], Body, Req),
- {ok, Req2, State};
-info(Message, Req, State) ->
- {loop, Req, State, hibernate}.
-
-terminate(Req, State) ->
- ok.
-```
-
-It is of course possible to combine both type of handlers together as long as
-you return the proper tuple from init/3.
-
-**Note**: versions prior to `0.4.0` used the
-[quoted](https://github.com/klaar/quoted.erl) library instead of the built in
-`cowboy_http:urldecode/2` function. If you want to retain this you must add it
-as a dependency to your application and add the following cowboy_http_protocol
-option:
-
-``` erlang
- {urldecode, {fun quoted:from_url/2, quoted:make([])}}
-```
-
-Continue reading to learn how to dispatch rules and handle requests.
-
-Dispatch rules
---------------
-
-Cowboy allows you to dispatch HTTP requests directly to a specific handler
-based on the hostname and path information from the request. It also lets
-you define static options for the handler directly in the rules.
-
-To match the hostname and path, Cowboy requires a list of tokens. For
-example, to match the "ninenines.eu" domain name, you must specify
-`[<<"ninenines">>, <<"eu">>]`. Or, to match the "/path/to/my/resource"
-you must use `[<<"path">>, <<"to">>, <<"my">>, <<"resource">>]`. All the
-tokens must be given as binary.
-
-You can use the special token `'_'` (the atom underscore) to indicate that
-you accept anything in that position. For example if you have both
-"ninenines.eu" and "ninenines.fr" domains, you can use the match spec
-`[<<"ninenines">>, '_']` to match any top level extension.
-
-Finally, you can also match multiple leading segments of the domain name and
-multiple trailing segments of the request path using the atom `'...'` (the atom
-ellipsis) respectively as the first host token or the last path token. For
-example, host rule `['...', <<"ninenines">>, <<"eu">>]` can match both
-"cowboy.bugs.ninenines.eu" and "ninenines.eu" and path rule
-`[<<"projects">>, '...']` can match both "/projects" and
-"/projects/cowboy/issues/42". The host leading segments and the path trailing
-segments can later be retrieved through `cowboy_http_req:host_info/1` and
-`cowboy_http_req:path_info/1`.
-
-Any other atom used as a token will bind the value to this atom when
-matching. To follow on our hostnames example, `[<<"ninenines">>, ext]`
-would bind the values `<<"eu">>` and `<<"fr">>` to the ext atom, that you
-can later retrieve in your handler by calling `cowboy_http_req:binding/{2,3}`.
-
-You can also accept any match spec by using the atom `'_'` directly instead of
-a list of tokens. Our hello world example above uses this to forward all
-requests to a single handler.
-
-There is currently no way to match multiple tokens at once.
-
-Requests handling
------------------
-
-Requests are passed around in the Request variable. Although they are
-defined as a record, it is recommended to access them only through the
-cowboy_http_req module API.
-
-You can retrieve the HTTP method, HTTP version, peer address and port,
-host tokens, raw host, used port, path tokens, raw path, query string
-values, bound values from the dispatch step, header values from the
-request. You can also read the request body, if any, optionally parsing
-it as a query string. Finally, the request allows you to send a response
-to the client.
-
-See the cowboy_http_req module for more information.
-
-Websockets
-----------
-
-The Websocket protocol is built upon the HTTP protocol. It first sends
-an HTTP request for an handshake, performs it and then switches
-to Websocket. Therefore you need to write a standard HTTP handler to
-confirm the handshake should be completed and then the Websocket-specific
-callbacks.
-
-A simple handler doing nothing but sending a repetitive message using
-Websocket would look like this:
-
-``` erlang
--module(my_ws_handler).
--export([init/3]).
--export([websocket_init/3, websocket_handle/3,
- websocket_info/3, websocket_terminate/3]).
-
-init({tcp, http}, Req, Opts) ->
- {upgrade, protocol, cowboy_http_websocket}.
-
-websocket_init(TransportName, Req, _Opts) ->
- erlang:start_timer(1000, self(), <<"Hello!">>),
- {ok, Req, undefined_state}.
-
-websocket_handle({text, Msg}, Req, State) ->
- {reply, {text, << "That's what she said! ", Msg/binary >>}, Req, State};
-websocket_handle(_Data, Req, State) ->
- {ok, Req, State}.
-
-websocket_info({timeout, _Ref, Msg}, Req, State) ->
- erlang:start_timer(1000, self(), <<"How' you doin'?">>),
- {reply, {text, Msg}, Req, State};
-websocket_info(_Info, Req, State) ->
- {ok, Req, State}.
-
-websocket_terminate(_Reason, _Req, _State) ->
- ok.
-```
-
-Of course you can have an HTTP handler doing both HTTP and Websocket
-handling, but for the sake of this example we're ignoring the HTTP
-part entirely.
-
-As the Websocket protocol is still a draft the API is subject to change
-regularly when support to the most recent drafts gets added. Features may
-be added, changed or removed before the protocol gets finalized. Cowboy
-tries to implement all drafts transparently and give a single interface to
-handle them all, however.
-
-Using Cowboy with other protocols
----------------------------------
-
-One of the strengths of Cowboy is of course that you can use it with any
-protocol you want. The only downside is that if it's not HTTP, you'll
-probably have to write the protocol handler yourself.
-
-The only exported function a protocol handler needs is the start_link/4
-function, with arguments ListenerPid, Socket, Transport and Opts. ListenerPid
-is the pid to the listener's gen_server, managing the connections. Socket is of
-course the client socket; Transport is the module name of the chosen transport
-handler and Opts is protocol options defined when starting the listener.
-
-After initializing your protocol, it is recommended to call the
-function cowboy:accept_ack/1 with the ListenerPid as argument,
-as it will ensure Cowboy has been able to fully initialize the socket.
-Anything you do past this point is up to you!
-
-If you need to change some socket options, like enabling raw mode for example,
-you can call the <em>Transport:setopts/2</em> function. It is the protocol's
-responsability to manage the socket usage, there should be no need for an user
-to specify that kind of options while starting a listener.
-
-You should definitely look at the cowboy_http_protocol module for a great
-example of fast request handling if you need to. Otherwise it's probably
-safe to use `{active, once}` mode and handle everything as it comes.
-
-Note that while you technically can run a protocol handler directly as a
-gen_server or a gen_fsm, it's probably not a good idea, as the only call
-you'll ever receive from Cowboy is the start_link/4 call. On the other
-hand, feel free to write a very basic protocol handler which then forwards
-requests to a gen_server or gen_fsm. By doing so however you must take
-care to supervise their processes as Cowboy only knows about the protocol
-handler itself.
View
101 deps/cowboy-0.6.0/ROADMAP.md
@@ -1,101 +0,0 @@
-ROADMAP
-=======
-
-This document explains in as much details as possible the
-list of planned changes and work to be done on the Cowboy
-server. It is non-exhaustive and subject to change. Items
-are not ordered.
-
-* Write more, better examples.
-
- The first step would be to port misultin's examples
- to Cowboy. Then these examples could be completed with
- examples for Cowboy specific features.
-
- The extend/cowboy_examples is to be used for this. As
- it is a separate repository, we can organize the file
- structure as appropriate. Ideally we would have one
- complete example per folder.
-
- Examples should be commented. They may or may not be
- used for writing the user guides.
-
-* Write user guides.
-
- We currently have good API documentation, but no step
- by step user guides.
-
-* Write more, better tests.
-
- Amongst the areas less tested there is protocol upgrades
- and the REST handler.
-
- Current tests should be completed with unit tests
- where applicable. We should probably also test the
- dependencies used, like erlang:decode_packet/3.
-
- While eunit and ct tests are fine, some parts of the
- code could benefit from PropEr tests.
-
-* Continuous performance testing.
-
- Initially dubbed the Horse project, Cowboy could benefit
- from a continuous performance testing tool that would
- allow us to easily compare the impact of the changes we
- are introducing, similar to what the Phoronix test suite
- allows.
-
- Depending on the test it may be interesting to compare
- Cowboy to other servers and eventually take ideas from
- the servers that outperform Cowboy for the task being tested.
-
-* Improve HTTP/1.0 support.
-
- Most of the work on Cowboy has been done with HTTP/1.1
- in mind. But there is still a need for HTTP/1.0 code in
- Cowboy. The server code should be reviewed and tested
- to ensure compatibility with remaining HTTP/1.0 products.
-
-* HTTP 100 Continue support.
-
- Tools like curl expect a 100 Continue before sending a
- request body by default.
-
-* Complete the work on Websockets.
-
- Now that the Autobahn test suite is available (make inttests),
- we have a definite way to know whether Cowboy's implementation
- of Websockets is right. The work can thus be completed. The
- remaining task is proper UTF8 handling.
-
-* SPDY support.
-
- While SPDY probably won't be added directly to Cowboy, work
- has been started on making Cowboy use SPDY.
-
-* Transport upgrades.
-
- Some protocols allow an upgrade from TCP to SSL without
- closing the connection. This is currently not possible
- through the Cowboy API.
-
-* Resizing the acceptor pool.
-
- We should be able to add more acceptors to a pool but also
- to remove some of them as needed.
-
-* Simplified dispatch list.
-
- For convenience purposes, the dispatch list should allow
- lists instead of binaries. The lists can be converted to
- binary by Cowboy at listener initialization.
-
- There has also been discussion on allowing the dispatch
- list to be hierarchical.
-
-* Add Transport:secure/0.
-
- Currently Cowboy checks if a connection is secure by
- checking if its name is 'ssl'. This isn't a very modular
- solution, adding an API function that returns whether
- a connection is secure would fix that issue.
View
1 deps/cowboy-0.6.0/cover.spec
@@ -1 +0,0 @@
-{incl_app, cowboy, details}.
View
4 deps/cowboy-0.6.0/doc/overview.edoc
@@ -1,4 +0,0 @@
-@author Lo�c Hoguin <essen@ninenines.eu>
-@copyright 2011-2012 Lo�c Hoguin
-@version HEAD
-@title Small, fast, modular HTTP server.
View
0 deps/cowboy-0.6.0/ebin/.gitignore
No changes.
View
16 deps/cowboy-0.6.0/ebin/cowboy.app
@@ -1,16 +0,0 @@
-{application,cowboy,
- [{description,"Small, fast, modular HTTP server."},
- {vsn,"0.6.0"},
- {modules,[cowboy,cowboy_acceptor,cowboy_acceptors_sup,
- cowboy_app,cowboy_bstr,cowboy_client,cowboy_clock,
- cowboy_cookies,cowboy_dispatcher,cowboy_http,
- cowboy_http_handler,cowboy_http_protocol,
- cowboy_http_req,cowboy_http_rest,cowboy_http_static,
- cowboy_http_websocket,cowboy_http_websocket_handler,
- cowboy_listener,cowboy_listener_sup,cowboy_multipart,
- cowboy_protocol,cowboy_requests_sup,
- cowboy_ssl_transport,cowboy_sup,cowboy_tcp_transport]},
- {registered,[cowboy_clock,cowboy_sup]},
- {applications,[kernel,stdlib]},
- {mod,{cowboy_app,[]}},
- {env,[]}]}.
View
BIN deps/cowboy-0.6.0/ebin/cowboy.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_acceptor.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_acceptors_sup.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_app.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_bstr.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_client.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_clock.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_cookies.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_dispatcher.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_http.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_http_handler.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_http_protocol.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_http_req.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_http_rest.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_http_static.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_http_websocket.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_http_websocket_handler.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_listener.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_listener_sup.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_multipart.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_protocol.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_requests_sup.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_ssl_transport.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_sup.beam
Binary file not shown.
View
BIN deps/cowboy-0.6.0/ebin/cowboy_tcp_transport.beam
Binary file not shown.
View
6 deps/cowboy-0.6.0/examples/README.md
@@ -1,6 +0,0 @@
-Cowboy examples
-===============
-
-The Cowboy examples can be found in a separate repository:
-
-* https://github.com/extend/cowboy_examples
View
58 deps/cowboy-0.6.0/include/http.hrl
@@ -1,58 +0,0 @@
-%% Copyright (c) 2011-2012, Loïc Hoguin <essen@ninenines.eu>
-%% Copyright (c) 2011, Anthony Ramine <nox@dev-extend.eu>
-%%
-%% Permission to use, copy, modify, and/or distribute this software for any
-%% purpose with or without fee is hereby granted, provided that the above
-%% copyright notice and this permission notice appear in all copies.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
--record(http_req, {
- %% Transport.
- socket = undefined :: undefined | inet:socket(),
- transport = undefined :: undefined | module(),
- connection = keepalive :: keepalive | close,
-
- %% Request.
- pid = undefined :: pid(),
- method = 'GET' :: cowboy_http:method(),
- version = {1, 1} :: cowboy_http:version(),
- peer = undefined :: undefined |
- {inet:ip_address(), inet:port_number()},
- host = undefined :: undefined | cowboy_dispatcher:tokens(),
- host_info = undefined :: undefined | cowboy_dispatcher:tokens(),
- raw_host = undefined :: undefined | binary(),
- port = undefined :: undefined | inet:port_number(),
- path = undefined :: undefined | '*' | cowboy_dispatcher:tokens(),
- path_info = undefined :: undefined | cowboy_dispatcher:tokens(),
- raw_path = undefined :: undefined | binary(),
- qs_vals = undefined :: undefined | list({binary(), binary() | true}),
- raw_qs = undefined :: undefined | binary(),
- bindings = undefined :: undefined | cowboy_dispatcher:bindings(),
- headers = [] :: cowboy_http:headers(),
- p_headers = [] :: [any()], %% @todo Improve those specs.
- cookies = undefined :: undefined | [{binary(), binary()}],
- meta = [] :: [{atom(), any()}],
-
- %% Request body.
- body_state = waiting :: waiting | done | {stream, fun(), any(), fun()}
- | {multipart, non_neg_integer(), fun()},
- buffer = <<>> :: binary(),
-
- %% Response.
- resp_state = waiting :: locked | waiting | chunks | done,
- resp_headers = [] :: cowboy_http:headers(),
- resp_body = <<>> :: iodata() | {non_neg_integer(),
- fun(() -> {sent, non_neg_integer()})},
-
- %% Functions.
- onresponse = undefined :: undefined | fun((cowboy_http:status(),
- cowboy_http:headers(), #http_req{}) -> #http_req{}),
- urldecode :: {fun((binary(), T) -> binary()), T}
-}).
View
6 deps/cowboy-0.6.0/rebar.config
@@ -1,6 +0,0 @@
-{erl_opts, [
-%% bin_opt_info,
-%% warn_missing_spec,
- warnings_as_errors,
- warn_export_all
-]}.
View
7 deps/cowboy-0.6.0/rebar.tests.config
@@ -1,7 +0,0 @@
-{cover_enabled, true}.
-{deps, [
- {proper, "1.0",
- {git, "git://github.com/manopapad/proper.git", {tag, "v1.0"}}}
-]}.
-{eunit_opts, [verbose, {report, {eunit_surefire, [{dir, "."}]}}]}.
-{erl_opts, []}.
View
26 deps/cowboy-0.6.0/src/cowboy.app.src
@@ -1,26 +0,0 @@
-%% Copyright (c) 2011-2012, Loïc Hoguin <essen@ninenines.eu>
-%%
-%% Permission to use, copy, modify, and/or distribute this software for any
-%% purpose with or without fee is hereby granted, provided that the above
-%% copyright notice and this permission notice appear in all copies.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-{application, cowboy, [
- {description, "Small, fast, modular HTTP server."},
- {vsn, "0.6.0"},
- {modules, []},
- {registered, [cowboy_clock, cowboy_sup]},
- {applications, [
- kernel,
- stdlib
- ]},
- {mod, {cowboy_app, []}},
- {env, []}
-]}.
View
114 deps/cowboy-0.6.0/src/cowboy.erl
@@ -1,114 +0,0 @@
-%% Copyright (c) 2011-2012, Loïc Hoguin <essen@ninenines.eu>
-%%
-%% Permission to use, copy, modify, and/or distribute this software for any
-%% purpose with or without fee is hereby granted, provided that the above
-%% copyright notice and this permission notice appear in all copies.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-%% @doc Cowboy API to start and stop listeners.
--module(cowboy).
-
--export([start_listener/6, stop_listener/1, child_spec/6, accept_ack/1,
- get_protocol_options/1, set_protocol_options/2]).
-
-%% @doc Start a listener for the given transport and protocol.
-%%
-%% A listener is effectively a pool of <em>NbAcceptors</em> acceptors.
-%% Acceptors accept connections on the given <em>Transport</em> and forward
-%% requests to the given <em>Protocol</em> handler. Both transport and protocol
-%% modules can be given options through the <em>TransOpts</em> and the
-%% <em>ProtoOpts</em> arguments. Available options are documented in the
-%% <em>listen</em> transport function and in the protocol module of your choice.
-%%
-%% All acceptor and request processes are supervised by the listener.
-%%
-%% It is recommended to set a large enough number of acceptors to improve
-%% performance. The exact number depends of course on your hardware, on the
-%% protocol used and on the number of expected simultaneous connections.
-%%
-%% The <em>Transport</em> option <em>max_connections</em> allows you to define
-%% the maximum number of simultaneous connections for this listener. It defaults
-%% to 1024. See <em>cowboy_listener</em> for more details on limiting the number
-%% of connections.
-%%
-%% Although Cowboy includes a <em>cowboy_http_protocol</em> handler, other
-%% handlers can be created for different protocols like IRC, FTP and more.
-%%
-%% <em>Ref</em> can be used to stop the listener later on.
--spec start_listener(any(), non_neg_integer(), module(), any(), module(), any())
- -> {ok, pid()}.
-start_listener(Ref, NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts)
- when is_integer(NbAcceptors) andalso is_atom(Transport)
- andalso is_atom(Protocol) ->
- supervisor:start_child(cowboy_sup, child_spec(Ref, NbAcceptors,
- Transport, TransOpts, Protocol, ProtoOpts)).
-
-%% @doc Stop a listener identified by <em>Ref</em>.
--spec stop_listener(any()) -> ok | {error, not_found}.
-stop_listener(Ref) ->
- case supervisor:terminate_child(cowboy_sup, {cowboy_listener_sup, Ref}) of
- ok ->
- supervisor:delete_child(cowboy_sup, {cowboy_listener_sup, Ref});
- {error, Reason} ->
- {error, Reason}
- end.
-
-%% @doc Return a child spec suitable for embedding.
-%%
-%% When you want to embed cowboy in another application, you can use this
-%% function to create a <em>ChildSpec</em> suitable for use in a supervisor.
-%% The parameters are the same as in <em>start_listener/6</em> but rather
-%% than hooking the listener to the cowboy internal supervisor, it just returns
-%% the spec.
--spec child_spec(any(), non_neg_integer(), module(), any(), module(), any())
- -> supervisor:child_spec().
-child_spec(Ref, NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts)
- when is_integer(NbAcceptors) andalso is_atom(Transport)
- andalso is_atom(Protocol) ->
- {{cowboy_listener_sup, Ref}, {cowboy_listener_sup, start_link, [
- NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts
- ]}, permanent, 5000, supervisor, [cowboy_listener_sup]}.
-
-%% @doc Acknowledge the accepted connection.
-%%
-%% Effectively used to make sure the socket control has been given to
-%% the protocol process before starting to use it.
--spec accept_ack(pid()) -> ok.
-accept_ack(ListenerPid) ->
- receive {shoot, ListenerPid} -> ok end.
-
-%% @doc Return the current protocol options for the given listener.
--spec get_protocol_options(any()) -> any().
-get_protocol_options(Ref) ->
- ListenerPid = ref_to_listener_pid(Ref),
- {ok, ProtoOpts} = cowboy_listener:get_protocol_options(ListenerPid),
- ProtoOpts.
-
-%% @doc Upgrade the protocol options for the given listener.
-%%
-%% The upgrade takes place at the acceptor level, meaning that only the
-%% newly accepted connections receive the new protocol options. This has
-%% no effect on the currently opened connections.
--spec set_protocol_options(any(), any()) -> ok.
-set_protocol_options(Ref, ProtoOpts) ->
- ListenerPid = ref_to_listener_pid(Ref),
- ok = cowboy_listener:set_protocol_options(ListenerPid, ProtoOpts).
-
-%% Internal.
-
--spec ref_to_listener_pid(any()) -> pid().
-ref_to_listener_pid(Ref) ->
- Children = supervisor:which_children(cowboy_sup),
- {_, ListenerSupPid, _, _} = lists:keyfind(
- {cowboy_listener_sup, Ref}, 1, Children),
- ListenerSupChildren = supervisor:which_children(ListenerSupPid),
- {_, ListenerPid, _, _} = lists:keyfind(
- cowboy_listener, 1, ListenerSupChildren),
- ListenerPid.
View
57 deps/cowboy-0.6.0/src/cowboy_acceptor.erl
@@ -1,57 +0,0 @@
-%% Copyright (c) 2011-2012, Loïc Hoguin <essen@ninenines.eu>
-%%
-%% Permission to use, copy, modify, and/or distribute this software for any
-%% purpose with or without fee is hereby granted, provided that the above
-%% copyright notice and this permission notice appear in all copies.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-%% @private
--module(cowboy_acceptor).
-
--export([start_link/6]). %% API.
--export([acceptor/7]). %% Internal.
-
-%% API.
-
--spec start_link(inet:socket(), module(), module(), any(),
- pid(), pid()) -> {ok, pid()}.
-start_link(LSocket, Transport, Protocol, Opts,
- ListenerPid, ReqsSup) ->
- Pid = spawn_link(?MODULE, acceptor,
- [LSocket, Transport, Protocol, Opts, 1, ListenerPid, ReqsSup]),
- {ok, Pid}.
-
-%% Internal.
-
--spec acceptor(inet:socket(), module(), module(), any(),
- non_neg_integer(), pid(), pid()) -> no_return().
-acceptor(LSocket, Transport, Protocol, Opts, OptsVsn, ListenerPid, ReqsSup) ->
- Res = case Transport:accept(LSocket, 2000) of
- {ok, CSocket} ->
- {ok, Pid} = supervisor:start_child(ReqsSup,
- [ListenerPid, CSocket, Transport, Protocol, Opts]),
- Transport:controlling_process(CSocket, Pid),
- cowboy_listener:add_connection(ListenerPid,
- default, Pid, OptsVsn);
- {error, timeout} ->
- cowboy_listener:check_upgrades(ListenerPid, OptsVsn);
- {error, _Reason} ->
- %% @todo Probably do something here. If the socket was closed,
- %% we may want to try and listen again on the port?
- ok
- end,
- case Res of
- ok ->
- ?MODULE:acceptor(LSocket, Transport, Protocol,
- Opts, OptsVsn, ListenerPid, ReqsSup);
- {upgrade, Opts2, OptsVsn2} ->
- ?MODULE:acceptor(LSocket, Transport, Protocol,
- Opts2, OptsVsn2, ListenerPid, ReqsSup)
- end.
View
48 deps/cowboy-0.6.0/src/cowboy_acceptors_sup.erl
@@ -1,48 +0,0 @@
-%% Copyright (c) 2011-2012, Loïc Hoguin <essen@ninenines.eu>
-%%
-%% Permission to use, copy, modify, and/or distribute this software for any
-%% purpose with or without fee is hereby granted, provided that the above
-%% copyright notice and this permission notice appear in all copies.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-%% @private
--module(cowboy_acceptors_sup).
--behaviour(supervisor).
-
--export([start_link/7]). %% API.
--export([init/1]). %% supervisor.
-
-%% API.
-
--spec start_link(non_neg_integer(), module(), any(),
- module(), any(), pid(), pid()) -> {ok, pid()}.
-start_link(NbAcceptors, Transport, TransOpts,
- Protocol, ProtoOpts, ListenerPid, ReqsPid) ->
- supervisor:start_link(?MODULE, [NbAcceptors, Transport, TransOpts,
- Protocol, ProtoOpts, ListenerPid, ReqsPid]).
-
-%% supervisor.
-
--spec init([any()]) -> {'ok', {{'one_for_one', 10, 10}, [{
- any(), {atom() | tuple(), atom(), 'undefined' | [any()]},
- 'permanent' | 'temporary' | 'transient',
- 'brutal_kill' | 'infinity' | non_neg_integer(),
- 'supervisor' | 'worker',
- 'dynamic' | [atom() | tuple()]}]
-}}.
-init([NbAcceptors, Transport, TransOpts,
- Protocol, ProtoOpts, ListenerPid, ReqsPid]) ->
- {ok, LSocket} = Transport:listen(TransOpts),
- Procs = [{{acceptor, self(), N}, {cowboy_acceptor, start_link, [
- LSocket, Transport, Protocol, ProtoOpts,
- ListenerPid, ReqsPid
- ]}, permanent, brutal_kill, worker, []}
- || N <- lists:seq(1, NbAcceptors)],
- {ok, {{one_for_one, 10, 10}, Procs}}.
View
53 deps/cowboy-0.6.0/src/cowboy_app.erl
@@ -1,53 +0,0 @@
-%% Copyright (c) 2011-2012, Loïc Hoguin <essen@ninenines.eu>
-%%
-%% Permission to use, copy, modify, and/or distribute this software for any
-%% purpose with or without fee is hereby granted, provided that the above
-%% copyright notice and this permission notice appear in all copies.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-%% @private
--module(cowboy_app).
--behaviour(application).
-
--export([start/2, stop/1, profile_output/0]). %% API.
-
--type application_start_type() :: normal
- | {takeover, node()} | {failover, node()}.
-
-%% API.
-
--spec start(application_start_type(), any()) -> {ok, pid()}.
-start(_Type, _Args) ->
- consider_profiling(),
- cowboy_sup:start_link().
-
--spec stop(any()) -> ok.
-stop(_State) ->
- ok.
-
--spec profile_output() -> ok.
-profile_output() ->
- eprof:stop_profiling(),
- eprof:log("procs.profile"),
- eprof:analyze(procs),
- eprof:log("total.profile"),
- eprof:analyze(total).
-
-%% Internal.
-
--spec consider_profiling() -> profiling | not_profiling.
-consider_profiling() ->
- case application:get_env(profile) of
- {ok, true} ->
- {ok, _Pid} = eprof:start(),
- eprof:start_profiling([self()]);
- _ ->
- not_profiling
- end.
View
86 deps/cowboy-0.6.0/src/cowboy_bstr.erl
@@ -1,86 +0,0 @@
-%% Copyright (c) 2011-2012, Loïc Hoguin <essen@ninenines.eu>
-%%
-%% Permission to use, copy, modify, and/or distribute this software for any
-%% purpose with or without fee is hereby granted, provided that the above
-%% copyright notice and this permission notice appear in all copies.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-%% @doc Binary string manipulation.
--module(cowboy_bstr).
-
--export([to_lower/1]). %% Binary strings.
--export([char_to_lower/1, char_to_upper/1]). %% Characters.
-
-%% @doc Convert a binary string to lowercase.
--spec to_lower(binary()) -> binary().
-to_lower(L) ->
- << << (char_to_lower(C)) >> || << C >> <= L >>.
-
-%% @doc Convert [A-Z] characters to lowercase.
-%% @end
-%% We gain noticeable speed by matching each value directly.
--spec char_to_lower(char()) -> char().
-char_to_lower($A) -> $a;
-char_to_lower($B) -> $b;
-char_to_lower($C) -> $c;
-char_to_lower($D) -> $d;
-char_to_lower($E) -> $e;
-char_to_lower($F) -> $f;
-char_to_lower($G) -> $g;
-char_to_lower($H) -> $h;
-char_to_lower($I) -> $i;
-char_to_lower($J) -> $j;
-char_to_lower($K) -> $k;
-char_to_lower($L) -> $l;
-char_to_lower($M) -> $m;
-char_to_lower($N) -> $n;
-char_to_lower($O) -> $o;
-char_to_lower($P) -> $p;
-char_to_lower($Q) -> $q;
-char_to_lower($R) -> $r;
-char_to_lower($S) -> $s;
-char_to_lower($T) -> $t;
-char_to_lower($U) -> $u;
-char_to_lower($V) -> $v;
-char_to_lower($W) -> $w;
-char_to_lower($X) -> $x;
-char_to_lower($Y) -> $y;
-char_to_lower($Z) -> $z;
-char_to_lower(Ch) -> Ch.
-
-%% @doc Convert [a-z] characters to uppercase.
--spec char_to_upper(char()) -> char().
-char_to_upper($a) -> $A;
-char_to_upper($b) -> $B;
-char_to_upper($c) -> $C;
-char_to_upper($d) -> $D;
-char_to_upper($e) -> $E;
-char_to_upper($f) -> $F;
-char_to_upper($g) -> $G;
-char_to_upper($h) -> $H;
-char_to_upper($i) -> $I;
-char_to_upper($j) -> $J;
-char_to_upper($k) -> $K;
-char_to_upper($l) -> $L;
-char_to_upper($m) -> $M;
-char_to_upper($n) -> $N;
-char_to_upper($o) -> $O;
-char_to_upper($p) -> $P;
-char_to_upper($q) -> $Q;
-char_to_upper($r) -> $R;
-char_to_upper($s) -> $S;
-char_to_upper($t) -> $T;
-char_to_upper($u) -> $U;
-char_to_upper($v) -> $V;
-char_to_upper($w) -> $W;
-char_to_upper($x) -> $X;
-char_to_upper($y) -> $Y;
-char_to_upper($z) -> $Z;
-char_to_upper(Ch) -> Ch.
View
315 deps/cowboy-0.6.0/src/cowboy_client.erl
@@ -1,315 +0,0 @@
-%% -*- mode: erlang; tab-width: 4; indent-tabs-mode: t; -*-
-%%
-%% Copyright (c) 2012, Loïc Hoguin <essen@ninenines.eu>
-%%
-%% Permission to use, copy, modify, and/or distribute this software for any
-%% purpose with or without fee is hereby granted, provided that the above
-%% copyright notice and this permission notice appear in all copies.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-%% @private
--module(cowboy_client).
-
--export([init/1]).
--export([state/1]).
--export([transport/1]).
--export([close/1]).
-
--export([connect/4]).
--export([raw_request/2]).
--export([request/3]).
--export([request/4]).
--export([request/5]).
--export([response/1]).
--export([response_body/1]).
--export([skip_body/1]).
--export([stream_status/1]).
--export([stream_headers/1]).
--export([stream_header/1]).
--export([stream_body/1]).
-
--export([request_to_iolist/6]).
--export([auth_header/1]).
-
-
--record(client, {
- state = wait :: wait | request | response | response_body,
- opts = [] :: [any()],
- socket = undefined :: undefined | inet:socket(),
- transport = undefined :: module(),
- timeout = 5000 :: timeout(), %% @todo Configurable.
- buffer = <<>> :: binary(),
- connection = keepalive :: keepalive | close,
- version = {1, 1} :: cowboy_http:version(),
- response_body = undefined :: undefined | non_neg_integer()
-}).
-
--opaque client() :: #client{}.
--export_type([client/0]).
-
-init(Opts) ->
- {ok, #client{opts=Opts}}.
-
-state(#client{state=State}) ->
- State.
-
-transport(#client{socket=undefined}) ->
- {error, notconnected};
-transport(#client{transport=Transport, socket=Socket}) ->
- {ok, Transport, Socket}.
-
-close(Client=#client{socket=undefined}) ->
- {ok, Client#client{state=wait}};
-close(Client=#client{transport=Transport, socket=Socket}) ->
- Transport:close(Socket),
- {ok, Client#client{state=wait}}.
-
-connect(Transport, Host, Port, Client)
- when is_binary(Host) ->
- connect(Transport, binary_to_list(Host), Port, Client);
-connect(Transport, Host, Port, Client=#client{state=wait, opts=Opts})
- when is_atom(Transport), is_list(Host),
- is_integer(Port) ->
- case Transport:connect(Host, Port, Opts) of
- {ok, Socket} ->
- {ok, Client#client{state=request,
- socket=Socket,
- transport=Transport}};
- {error, _} = Err -> Err
- end.
-
-raw_request(Data, Client=#client{state=response_body}) ->
- {done, Client2} = skip_body(Client),
- raw_request(Data, Client2);
-raw_request(Data, Client=#client{
- state=request, socket=Socket, transport=Transport}) ->
- case Transport:send(Socket, Data) of
- ok ->
- {ok, Client};
- {error, _} = Err ->
- Err
- end.
-
-request(Method, URL, Client) ->
- request(Method, URL, [], <<>>, Client).
-
-request(Method, URL, Headers, Client) ->
- request(Method, URL, Headers, <<>>, Client).
-
-request(Method, URL, Headers, Body, Client=#client{state=response_body}) ->
- {done, Client2} = skip_body(Client),
- request(Method, URL, Headers, Body, Client2);
-request(Method, URL, Headers, Body, Client=#client{
- state=State, version=Version})
- when State =:= wait; State =:= request ->
- {Transport, FullHost, Host, Port, Path} = parse_url(URL),
- {ok, Client2} = case State of
- wait -> connect(Transport, Host, Port, Client);
- request -> {ok, Client}
- end,
- Data = request_to_iolist(Method, Headers, Body, Version, FullHost,
- Path),
- raw_request(Data, Client2).
-
-request_to_iolist(Method, Headers, Body, Version, FullHost, Path) ->
- VersionBin = cowboy_http:version_to_binary(Version),
- %% @todo do keepalive too, allow override...
- Headers2 = [{<<"Host">>, FullHost} | Headers],
- ContentLength = case iolist_size(Body) of
- 0 -> [];
- Length -> [{<<"Content-Length">>, integer_to_list(Length)}]
- end,
- HeadersData = [[Name, <<": ">>, Value, <<"\r\n">>]
- || {Name, Value} <-
- Headers2 ++ ContentLength],
- [Method, <<" ">>, Path, <<" ">>, VersionBin, <<"\r\n">>,
- HeadersData, <<"\r\n">>, Body].
-
-parse_url(<< "https://", Rest/binary >>) ->
- parse_url(Rest, cowboy_ssl_transport);
-parse_url(<< "http://", Rest/binary >>) ->
- parse_url(Rest, cowboy_tcp_transport);
-parse_url(URL) ->
- parse_url(URL, cowboy_tcp_transport).
-
-parse_url(URL, Transport) ->
- case binary:split(URL, <<"/">>) of
- [Peer] ->
- {Host, Port} = parse_peer(Peer, Transport),
- {Transport, Peer, Host, Port, <<"/">>};
- [Peer, Path] ->
- {Host, Port} = parse_peer(Peer, Transport),
- {Transport, Peer, Host, Port, [<<"/">>, Path]}
- end.
-
-parse_peer(Peer, Transport) ->
- case binary:split(Peer, <<":">>) of
- [Host] when Transport =:= cowboy_tcp_transport ->
- {binary_to_list(Host), 80};
- [Host] when Transport =:= cowboy_ssl_transport ->
- {binary_to_list(Host), 443};
- [Host, Port] ->
- {binary_to_list(Host), list_to_integer(binary_to_list(Port))}
- end.
-
-response(Client=#client{state=response_body}) ->
- {done, Client2} = skip_body(Client),
- response(Client2);
-response(Client=#client{state=request}) ->
- case stream_status(Client) of
- {ok, Status, _, Client2} ->
- case stream_headers(Client2) of
- {ok, Headers, Client3} ->
- {ok, Status, Headers, Client3};
- {error, Reason} ->
- {error, Reason}
- end;
- {error, Reason} ->
- {error, Reason}
- end.
-
-response_body(Client=#client{state=response_body}) ->
- response_body_loop(Client, <<>>).
-
-response_body_loop(Client, Acc) ->
- case stream_body(Client) of
- {ok, Data, Client2} ->
- response_body_loop(Client2, << Acc/binary, Data/binary >>);
- {done, Client2} ->
- {ok, Acc, Client2};
- {error, Reason} ->
- {error, Reason}
- end.
-
-skip_body(Client=#client{state=response_body}) ->
- case stream_body(Client) of
- {ok, _, Client2} -> skip_body(Client2);
- Done -> Done
- end.
-
-stream_status(Client=#client{state=State, buffer=Buffer})
- when State =:= request ->
- case binary:split(Buffer, <<"\r\n">>) of
- [Line, Rest] ->
- parse_status(Client#client{state=response, buffer=Rest}, Line);
- _ ->
- case recv(Client) of
- {ok, Data} ->
- Buffer2 = << Buffer/binary, Data/binary >>,
- stream_status(Client#client{buffer=Buffer2});
- {error, Reason} ->
- {error, Reason}
- end
- end.
-
-parse_status(Client, << "HTTP/", High, ".", Low, " ",
- S3, S2, S1, " ", StatusStr/binary >>)
- when High >= $0, High =< $9, Low >= $0, Low =< $9,
- S3 >= $0, S3 =< $9, S2 >= $0, S2 =< $9, S1 >= $0, S1 =< $9 ->
- Version = {High - $0, Low - $0},
- Status = (S3 - $0) * 100 + (S2 - $0) * 10 + S1 - $0,
- {ok, Status, StatusStr, Client#client{version=Version}}.
-
-stream_headers(Client=#client{state=State})
- when State =:= response ->
- stream_headers(Client, []).
-
-stream_headers(Client, Acc) ->
- case stream_header(Client) of
- {ok, Name, Value, Client2} ->
- stream_headers(Client2, [{Name, Value}|Acc]);
- {done, Client2} ->
- {ok, Acc, Client2};
- {error, Reason} ->
- {error, Reason}
- end.
-
-stream_header(Client=#client{state=State, buffer=Buffer,
- response_body=RespBody}) when State =:= response ->
- case binary:split(Buffer, <<"\r\n">>) of
- [<<>>, Rest] ->
- %% If we have a body, set response_body.
- Client2 = case RespBody of
- undefined -> Client#client{state=request};
- 0 -> Client#client{state=request};
- _ -> Client#client{state=response_body}
- end,
- {done, Client2#client{buffer=Rest}};
- [Line, Rest] ->
- %% @todo Do a better parsing later on.
- [Name, Value] = binary:split(Line, <<": ">>),
- Name2 = cowboy_bstr:to_lower(Name),
- Client2 = case Name2 of
- <<"content-length">> ->
- Length = list_to_integer(binary_to_list(Value)),
- if Length >= 0 -> ok end,
- Client#client{response_body=Length};
- _ ->
- Client
- end,
- {ok, Name2, Value, Client2#client{buffer=Rest}};
- _ ->
- case recv(Client) of
- {ok, Data} ->
- Buffer2 = << Buffer/binary, Data/binary >>,
- stream_header(Client#client{buffer=Buffer2});
- {error, Reason} ->
- {error, Reason}
- end
- end.
-
-stream_body(Client=#client{state=response_body, response_body=RespBody})
- when RespBody =:= undefined; RespBody =:= 0 ->
- {done, Client#client{state=request, response_body=undefined}};
-stream_body(Client=#client{state=response_body, buffer=Buffer,
- response_body=Length}) when is_integer(Length) ->
- case byte_size(Buffer) of
- 0 ->
- case recv(Client) of
- {ok, Body} when byte_size(Body) =< Length ->
- Length2 = Length - byte_size(Body),
- {ok, Body, Client#client{response_body=Length2}};
- {ok, Data} ->
- << Body:Length/binary, Rest/binary >> = Data,
- {ok, Body, Client#client{buffer=Rest,
- response_body=undefined}};
- {error, Reason} ->
- {error, Reason}
- end;
- N when N =< Length ->
- Length2 = Length - N,
- {ok, Buffer, Client#client{buffer= <<>>, response_body=Length2}};
- _ ->
- << Body:Length/binary, Rest/binary >> = Buffer,
- {ok, Body, Client#client{buffer=Rest, response_body=undefined}}
- end.
-
-recv(#client{socket=Socket, transport=Transport, timeout=Timeout}) ->
- Transport:recv(Socket, 0, Timeout).
-
-auth_header("") ->
- [];
-auth_header(AuthInfo) when is_list(AuthInfo) ->
- [{<<"Authorization">>,
- case string:tokens(AuthInfo, ":") of
- [User, Pass] ->
- encode_auth_header(User, Pass);
- [User] ->
- encode_auth_header(User)
- end}].
-
-%% @private
-encode_auth_header(User) ->
- encode_auth_header(User, "").
-
-%% @private
-encode_auth_header(User, Pass)
- when is_list(User), is_list(Pass) ->
- ["Basic ", base64:encode(User ++ ":" ++ Pass)].
View
254 deps/cowboy-0.6.0/src/cowboy_clock.erl
@@ -1,254 +0,0 @@
-%% Copyright (c) 2011-2012, Loïc Hoguin <essen@ninenines.eu>
-%%
-%% Permission to use, copy, modify, and/or distribute this software for any
-%% purpose with or without fee is hereby granted, provided that the above
-%% copyright notice and this permission notice appear in all copies.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-%% @doc Date and time related functions.
-%%
-%% While a gen_server process runs in the background to update
-%% the cache of formatted dates every second, all API calls are
-%% local and directly read from the ETS cache table, providing
-%% fast time and date computations.
--module(cowboy_clock).
--behaviour(gen_server).
-
--export([start_link/0, stop/0, rfc1123/0, rfc2109/1]). %% API.
--export([init/1, handle_call/3, handle_cast/2,
- handle_info/2, terminate/2, code_change/3]). %% gen_server.
-
--record(state, {
- universaltime = undefined :: undefined | calendar:datetime(),
- rfc1123 = <<>> :: binary(),
- tref = undefined :: undefined | timer:tref()
-}).
-
--define(SERVER, ?MODULE).
--define(TABLE, ?MODULE).
-
--include_lib("eunit/include/eunit.hrl").
-
-%% API.
-
-%% @private
--spec start_link() -> {ok, pid()}.
-start_link() ->
- gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
-
-%% @private
--spec stop() -> stopped.
-stop() ->
- gen_server:call(?SERVER, stop).
-
-%% @doc Return the current date and time formatted according to RFC-1123.
-%%
-%% This format is used in the <em>'Date'</em> header sent with HTTP responses.
--spec rfc1123() -> binary().
-rfc1123() ->
- ets:lookup_element(?TABLE, rfc1123, 2).
-
-%% @doc Return the current date and time formatted according to RFC-2109.
-%%
-%% This format is used in the <em>'Set-Cookie'</em> header sent with
-%% HTTP responses.
--spec rfc2109(calendar:datetime()) -> binary().
-rfc2109(LocalTime) ->
- {{YYYY,MM,DD},{Hour,Min,Sec}} =
- case calendar:local_time_to_universal_time_dst(LocalTime) of
- [Gmt] -> Gmt;
- [_,Gmt] -> Gmt;
- [] ->
- %% The localtime generated by cowboy_cookies may fall within
- %% the hour that is skipped by daylight savings time. If this
- %% is such a localtime, increment the localtime with one hour
- %% and try again, if this succeeds, subtracting the max_age
- %% from the resulting universaltime and converting to a local
- %% time will yield the original localtime.
- {Date, {Hour1, Min1, Sec1}} = LocalTime,
- LocalTime2 = {Date, {Hour1 + 1, Min1, Sec1}},
- case calendar:local_time_to_universal_time_dst(LocalTime2) of
- [Gmt] -> Gmt;
- [_,Gmt] -> Gmt
- end
- end,
- Wday = calendar:day_of_the_week({YYYY,MM,DD}),
- DayBin = pad_int(DD),
- YearBin = list_to_binary(integer_to_list(YYYY)),
- HourBin = pad_int(Hour),
- MinBin = pad_int(Min),
- SecBin = pad_int(Sec),
- WeekDay = weekday(Wday),
- Month = month(MM),
- <<WeekDay/binary, ", ",
- DayBin/binary, " ", Month/binary, " ",
- YearBin/binary, " ",
- HourBin/binary, ":",
- MinBin/binary, ":",
- SecBin/binary, " GMT">>.
-
-%% gen_server.
-
-%% @private
--spec init([]) -> {ok, #state{}}.
-init([]) ->
- ?TABLE = ets:new(?TABLE, [set, protected,
- named_table, {read_concurrency, true}]),
- T = erlang:universaltime(),
- B = update_rfc1123(<<>>, undefined, T),
- {ok, TRef} = timer:send_interval(1000, update),
- ets:insert(?TABLE, {rfc1123, B}),
- {ok, #state{universaltime=T, rfc1123=B, tref=TRef}}.
-
-%% @private
--spec handle_call(_, _, State)
- -> {reply, ignored, State} | {stop, normal, stopped, State}.
-handle_call(stop, _From, State=#state{tref=TRef}) ->
- {ok, cancel} = timer:cancel(TRef),
- {stop, normal, stopped, State};
-handle_call(_Request, _From, State) ->
- {reply, ignored, State}.
-
-%% @private
--spec handle_cast(_, State) -> {noreply, State}.
-handle_cast(_Msg, State) ->
- {noreply, State}.
-
-%% @private
--spec handle_info(_, State) -> {noreply, State}.
-handle_info(update, #state{universaltime=Prev, rfc1123=B1, tref=TRef}) ->
- T = erlang:universaltime(),
- B2 = update_rfc1123(B1, Prev, T),
- ets:insert(?TABLE, {rfc1123, B2}),
- {noreply, #state{universaltime=T, rfc1123=B2, tref=TRef}};
-handle_info(_Info, State) ->
- {noreply, State}.
-
-%% @private
--spec terminate(_, _) -> ok.
-terminate(_Reason, _State) ->
- ok.
-
-%% @private
--spec code_change(_, State, _) -> {ok, State}.
-code_change(_OldVsn, State, _Extra) ->
- {ok, State}.
-
-%% Internal.
-
--spec update_rfc1123(binary(), undefined | calendar:datetime(),
- calendar:datetime()) -> binary().
-update_rfc1123(Bin, Now, Now) ->
- Bin;
-update_rfc1123(<< Keep:23/binary, _/bits >>,
- {Date, {H, M, _}}, {Date, {H, M, S}}) ->
- << Keep/binary, (pad_int(S))/binary, " GMT" >>;
-update_rfc1123(<< Keep:20/binary, _/bits >>,
- {Date, {H, _, _}}, {Date, {H, M, S}}) ->
- << Keep/binary, (pad_int(M))/binary, $:, (pad_int(S))/binary, " GMT" >>;
-update_rfc1123(<< Keep:17/binary, _/bits >>, {Date, _}, {Date, {H, M, S}}) ->
- << Keep/binary, (pad_int(H))/binary, $:, (pad_int(M))/binary,
- $:, (pad_int(S))/binary, " GMT" >>;
-update_rfc1123(<< _:7/binary, Keep:10/binary, _/bits >>,
- {{Y, Mo, _}, _}, {Date = {Y, Mo, D}, {H, M, S}}) ->
- Wday = calendar:day_of_the_week(Date),
- << (weekday(Wday))/binary, ", ", (pad_int(D))/binary, Keep/binary,
- (pad_int(H))/binary, $:, (pad_int(M))/binary,
- $:, (pad_int(S))/binary, " GMT" >>;
-update_rfc1123(<< _:11/binary, Keep:6/binary, _/bits >>,
- {{Y, _, _}, _}, {Date = {Y, Mo, D}, {H, M, S}}) ->
- Wday = calendar:day_of_the_week(Date),
- << (weekday(Wday))/binary, ", ", (pad_int(D))/binary, " ",
- (month(Mo))/binary, Keep/binary,
- (pad_int(H))/binary, $:, (pad_int(M))/binary,
- $:, (pad_int(S))/binary, " GMT" >>;
-update_rfc1123(_, _, {Date = {Y, Mo, D}, {H, M, S}}) ->
- Wday = calendar:day_of_the_week(Date),
- << (weekday(Wday))/binary, ", ", (pad_int(D))/binary, " ",
- (month(Mo))/binary, " ", (list_to_binary(integer_to_list(Y)))/binary,
- " ", (pad_int(H))/binary, $:, (pad_int(M))/binary,
- $:, (pad_int(S))/binary, " GMT" >>.
-
-%% Following suggestion by MononcQc on #erlounge.
--spec pad_int(0..59) -> binary().
-pad_int(X) when X < 10 ->
- << $0, ($0 + X) >>;
-pad_int(X) ->
- list_to_binary(integer_to_list(X)).
-
--spec weekday(1..7) -> <<_:24>>.
-weekday(1) -> <<"Mon">>;
-weekday(2) -> <<"Tue">>;
-weekday(3) -> <<"Wed">>;
-weekday(4) -> <<"Thu">>;
-weekday(5) -> <<"Fri">>;
-weekday(6) -> <<"Sat">>;
-weekday(7) -> <<"Sun">>.
-
--spec month(1..12) -> <<_:24>>.
-month( 1) -> <<"Jan">>;
-month( 2) -> <<"Feb">>;
-month( 3) -> <<"Mar">>;
-month( 4) -> <<"Apr">>;
-month( 5) -> <<"May">>;
-month( 6) -> <<"Jun">>;
-month( 7) -> <<"Jul">>;
-month( 8) -> <<"Aug">>;
-month( 9) -> <<"Sep">>;
-month(10) -> <<"Oct">>;
-month(11) -> <<"Nov">>;
-month(12) -> <<"Dec">>.
-
-%% Tests.
-
--ifdef(TEST).
-
-update_rfc1123_test_() ->
- Tests = [
- {<<"Sat, 14 May 2011 14:25:33 GMT">>, undefined,
- {{2011, 5, 14}, {14, 25, 33}}, <<>>},
- {<<"Sat, 14 May 2011 14:25:33 GMT">>, {{2011, 5, 14}, {14, 25, 33}},
- {{2011, 5, 14}, {14, 25, 33}}, <<"Sat, 14 May 2011 14:25:33 GMT">>},
- {<<"Sat, 14 May 2011 14:25:34 GMT">>, {{2011, 5, 14}, {14, 25, 33}},
- {{2011, 5, 14}, {14, 25, 34}}, <<"Sat, 14 May 2011 14:25:33 GMT">>},
- {<<"Sat, 14 May 2011 14:26:00 GMT">>, {{2011, 5, 14}, {14, 25, 59}},
- {{2011, 5, 14}, {14, 26, 0}}, <<"Sat, 14 May 2011 14:25:59 GMT">>},
- {<<"Sat, 14 May 2011 15:00:00 GMT">>, {{2011, 5, 14}, {14, 59, 59}},
- {{2011, 5, 14}, {15, 0, 0}}, <<"Sat, 14 May 2011 14:59:59 GMT">>},
- {<<"Sun, 15 May 2011 00:00:00 GMT">>, {{2011, 5, 14}, {23, 59, 59}},
- {{2011, 5, 15}, { 0, 0, 0}}, <<"Sat, 14 May 2011 23:59:59 GMT">>},
- {<<"Wed, 01 Jun 2011 00:00:00 GMT">>, {{2011, 5, 31}, {23, 59, 59}},
- {{2011, 6, 1}, { 0, 0, 0}}, <<"Tue, 31 May 2011 23:59:59 GMT">>},
- {<<"Sun, 01 Jan 2012 00:00:00 GMT">>, {{2011, 5, 31}, {23, 59, 59}},
- {{2012, 1, 1}, { 0, 0, 0}}, <<"Sat, 31 Dec 2011 23:59:59 GMT">>}
- ],
- [{R, fun() -> R = update_rfc1123(B, P, N) end} || {R, P, N, B} <- Tests].
-
-pad_int_test_() ->
- Tests = [