mongrel2 0.15.1 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/ChangeLog CHANGED
@@ -1,8 +1,58 @@
1
+ 2012-03-07 Michael Granger <ged@FaerieMUD.org>
2
+
3
+ * README.rdoc, data/mongrel2/bootstrap.html,
4
+ data/mongrel2/css/master.css, data/mongrel2/js/websock-test.js,
5
+ data/mongrel2/websock-test.html, examples/config.rb, examples/ws-
6
+ echo.rb, lib/mongrel2/connection.rb, lib/mongrel2/handler.rb,
7
+ lib/mongrel2/websocket.rb:
8
+ Finished up WebSocket implementation.
9
+
10
+ - Added the class to API docs.
11
+ - Cleaned up and fixed a couple of bugs in the websocket echo server
12
+ backend.
13
+ - Fixed issues with encoding of incoming frame payloads.
14
+ - Added frame validation methods
15
+ [fea3cd02d23c] [github/master, tip]
16
+
17
+ 2012-03-05 Michael Granger <ged@FaerieMUD.org>
18
+
19
+ * data/mongrel2/bootstrap.html, data/mongrel2/css/master.css,
20
+ data/mongrel2/websock-test.html, examples/config.rb, examples/ws-
21
+ echo.rb, lib/mongrel2.rb, lib/mongrel2/handler.rb,
22
+ lib/mongrel2/request.rb, lib/mongrel2/testing.rb,
23
+ lib/mongrel2/websocket.rb, spec/lib/constants.rb,
24
+ spec/mongrel2/httprequest_spec.rb, spec/mongrel2/request_spec.rb,
25
+ spec/mongrel2/websocket_spec.rb:
26
+ Adding WebSocket (RFC6455) support
27
+ [0db6f3808f5a]
28
+
29
+ 2012-03-02 Michael Granger <ged@FaerieMUD.org>
30
+
31
+ * lib/mongrel2/handler.rb:
32
+ Log the method for unknown request types
33
+ [1de6b0f28ee6]
34
+
35
+ * examples/config.rb:
36
+ Remove the null filter from the examples config
37
+ [bbafaa425b68]
38
+
39
+ * .hgtags:
40
+ Added tag v0.15.1 for changeset 2bb88b311d68
41
+ [e6e61577d110]
42
+
43
+ * .hgsigs:
44
+ Added signature for changeset e943c9068b73
45
+ [2bb88b311d68] [v0.15.1]
46
+
47
+ * History.rdoc, lib/mongrel2.rb:
48
+ Bump patch version and update history.
49
+ [e943c9068b73]
50
+
1
51
  2012-03-01 Michael Granger <ged@FaerieMUD.org>
2
52
 
3
53
  * lib/mongrel2/connection.rb:
4
54
  Fix some comments/debug statements in Connection
5
- [16a888bc7999] [github/master, tip]
55
+ [16a888bc7999]
6
56
 
7
57
  * lib/mongrel2/config/host.rb:
8
58
  Make sure host deletes cascade to their routes
@@ -1,3 +1,8 @@
1
+ == v0.16.0 [2012-03-10] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ - Add WebSocket (RFC6455) support
4
+
5
+
1
6
  == v0.15.1 [2012-03-02] Michael Granger <ged@FaerieMUD.org>
2
7
 
3
8
  - Make sure Mongrel2::Config::Host deletes cascade to their routes
@@ -10,13 +10,16 @@ bin/m2sh.rb
10
10
  data/mongrel2/bootstrap.html
11
11
  data/mongrel2/config.sql
12
12
  data/mongrel2/css/master.css
13
+ data/mongrel2/js/websock-test.js
13
14
  data/mongrel2/mimetypes.sql
15
+ data/mongrel2/websock-test.html
14
16
  examples/README.txt
15
17
  examples/config.rb
16
18
  examples/helloworld-handler.rb
17
19
  examples/request-dumper.rb
18
20
  examples/request-dumper.tmpl
19
21
  examples/run
22
+ examples/ws-echo.rb
20
23
  lib/mongrel2.rb
21
24
  lib/mongrel2/config.rb
22
25
  lib/mongrel2/config/directory.rb
@@ -45,6 +48,7 @@ lib/mongrel2/request.rb
45
48
  lib/mongrel2/response.rb
46
49
  lib/mongrel2/table.rb
47
50
  lib/mongrel2/testing.rb
51
+ lib/mongrel2/websocket.rb
48
52
  lib/mongrel2/xmlrequest.rb
49
53
  spec/lib/constants.rb
50
54
  spec/lib/helpers.rb
@@ -72,4 +76,5 @@ spec/mongrel2/mixins_spec.rb
72
76
  spec/mongrel2/request_spec.rb
73
77
  spec/mongrel2/response_spec.rb
74
78
  spec/mongrel2/table_spec.rb
79
+ spec/mongrel2/websocket_spec.rb
75
80
  spec/mongrel2_spec.rb
@@ -4,25 +4,28 @@
4
4
 
5
5
  == Description
6
6
 
7
- Ruby-Mongrel2 is a complete Ruby (1.9-only) connector for
7
+ Ruby-Mongrel2 is a complete Ruby (1.9-only) connector for
8
8
  Mongrel2[http://mongrel2.org/].
9
9
 
10
10
  This library includes configuration-database ORM classes, a Ruby
11
11
  implementation of the 'm2sh' tool, a configuration DSL for generating config
12
- databases in pure Ruby, a Control port interface object, and handler classes
12
+ databases in pure Ruby, a Control port interface object, and handler classes
13
13
  for creating applications or higher-level frameworks.
14
14
 
15
- It differs from the original Mongrel2 Ruby library (m2r), and the
16
- mongrel2-rack library in several ways:
15
+
16
+ === Other Implementations
17
+
18
+ There are two other Mongrel2 Ruby libraries, +m2r+ and the +mongrel2-rack+
19
+ library. This implementation differs from them in several ways:
17
20
 
18
21
  * It uses the C extension for 0MQ (zmq) instead of the FFI one. If you
19
22
  strongly prefer the FFI library, both of the other Mongrel2 libraries use
20
23
  it, so you'll want to stick to one of them.
21
24
 
22
- * It doesn't come with a Rack handler, or Rails examples, or anything fancy. I
23
- intend to build my own webby framework bits around Mongrel2, and I thought
24
- maybe someone else might want to as well. If you don't, well again, there
25
- are two other libraries for you.
25
+ * It doesn't come with a Rack handler, or Rails examples, or anything too
26
+ fancy. I intend to build my own webby framework bits around Mongrel2, and
27
+ I thought maybe someone else might want to as well. If you don't, well
28
+ again, there are two other libraries for you.
26
29
 
27
30
  * It includes configuration stuff. I want to make tools that use the Mongrel2
28
31
  config database, so I wrote config classes. Sequel::Model made it
@@ -36,7 +39,8 @@ mongrel2-rack library in several ways:
36
39
  gem install mongrel2
37
40
 
38
41
 
39
- This library uses Jeremy Hinegardner's 'amalgalite' library for the config ORM classes, but it will also fall back to using the sqlite3 library instead:
42
+ This library uses Jeremy Hinegardner's 'amalgalite' library for the config ORM
43
+ classes, but it will also fall back to using the sqlite3 library instead:
40
44
 
41
45
  # Loading the sqlite3 library explicitly
42
46
  $ rspec -rsqlite3 -cfp spec
@@ -95,6 +99,7 @@ Mongrel2 sends:
95
99
  * Mongrel2::HTTPRequest
96
100
  * Mongrel2::JSONRequest
97
101
  * Mongrel2::XMLRequest
102
+ * Mongrel2::WebSocket::Frame
98
103
 
99
104
  These are all {overridable}[rdoc-ref:Mongrel2::Request.register_request_type]
100
105
  if you should want a more-specialized class for one of them.
@@ -527,6 +527,7 @@ class Mongrel2::M2SHCommand
527
527
 
528
528
  header "Reloading '%s'" % [ server.name ]
529
529
  control.reload
530
+ control.close
530
531
  message "done."
531
532
  end
532
533
  help :reload, "Reload the specified server's configuration"
@@ -540,6 +541,7 @@ class Mongrel2::M2SHCommand
540
541
 
541
542
  header "Stopping '%s' gracefully." % [ server.name ]
542
543
  control.stop
544
+ control.close
543
545
  message "done."
544
546
  end
545
547
  help :stop, "Stop the specified server gracefully"
@@ -1,27 +1,29 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <title>Ruby-Mongrel2 Examples</title>
5
- <link rel="stylesheet" href="/css/master.css" type="text/css" media="screen"
6
- title="no title" charset="utf-8" />
7
- </head>
8
- <body>
9
- <header>
10
- <hgroup>
11
- <h1>Ruby-Mongrel2 Examples</h1>
12
- </hgroup>
13
- </header>
3
+ <head>
4
+ <title>Ruby-Mongrel2 Examples</title>
5
+ <link rel="stylesheet" href="/css/master.css" type="text/css" media="screen"
6
+ title="no title" charset="utf-8" />
7
+ <meta charset="utf-8" />
8
+ </head>
9
+ <body>
10
+ <header>
11
+ <hgroup>
12
+ <h1>Ruby-Mongrel2 Examples</h1>
13
+ </hgroup>
14
+ </header>
14
15
 
15
- <section>
16
- <ol>
17
- <li><a href="/hello">Hello World</a> (<a href="/source/helloworld-handler.rb">source</a>) </li>
18
- <li><a href="/dump">Dump Request</a> (<a href="/source/request-dumper.rb">source</a>) </li>
19
- </ol>
20
- </section>
16
+ <section>
17
+ <ol>
18
+ <li><a href="/hello">Hello World</a> (<a href="/source/helloworld-handler.rb">source</a>) </li>
19
+ <li><a href="/dump">Dump Request</a> (<a href="/source/request-dumper.rb">source</a>) </li>
20
+ <li><a href="/websock-test.html">Web Socket Test</a></li>
21
+ </ol>
22
+ </section>
21
23
 
22
- <footer>
23
- <p>Copyright © 2011-2012 Michael Granger &lt;<a href="mailto:ged@FaerieMUD.org">ged@FaerieMUD.org</a>&gt;.</p>
24
- <p><tt>$Id: bootstrap.html,v e50e20d73e34 2012/02/27 17:27:33 ged $</tt></p>
25
- </footer>
26
- </body>
24
+ <footer>
25
+ <p>Copyright © 2011-2012 Michael Granger &lt;<a href="mailto:ged@FaerieMUD.org">ged@FaerieMUD.org</a>&gt;.</p>
26
+ <p><tt>$Id: bootstrap.html,v fea3cd02d23c 2012/03/07 16:07:50 ged $</tt></p>
27
+ </footer>
28
+ </body>
27
29
  </html>
@@ -1,4 +1,5 @@
1
- /* @override http://pelimer.pg.laika.com:8113/css/master.css */
1
+ /* @override http://pelimer.pg.laika.com:8113/css/master.css
2
+ http://localhost:8113/css/master.css */
2
3
 
3
4
  /*
4
5
  * Mongrel2 Examples Stylesheet
@@ -46,3 +47,31 @@ tbody th {
46
47
  vertical-align: top;
47
48
  white-space: pre;
48
49
  }
50
+
51
+
52
+ /*
53
+ * WebSocket tester styles
54
+ */
55
+
56
+ .websocket-test form {
57
+ margin: 2em 0;
58
+ padding: 2em;
59
+ border-radius: 0.5em;
60
+ background: rgba( 50,50,50, 0.5 );
61
+ }
62
+
63
+ .websocket-test form.socket-connected {
64
+ background: rgba( 0,150,0, 0.25 );
65
+ }
66
+
67
+ .websocket-test form input {
68
+ font-size: 1.4em;
69
+ width: 300px;
70
+ border: 1px solid #aaa;
71
+ background: #ddd;
72
+ }
73
+
74
+ .websocket-test form.socket-connected input {
75
+ background: #eee;
76
+ }
77
+
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Ruby-Mongrel2 Websocket Demo
3
+ * $Id$
4
+ *
5
+ * Author:
6
+ * - Michael Granger <ged@FaerieMUD.org>
7
+ *
8
+ */
9
+
10
+ var ws = null;
11
+
12
+ function writeToLog( msg ) {
13
+ $('#log').append( "<li>" + msg + "</li>\n");
14
+ }
15
+
16
+ function writeErrorLog( msg ) {
17
+ $('#log').append( "<li class=\"error\">" + msg + "</li>\n");
18
+ }
19
+
20
+ function onOpen( e ) {
21
+ console.debug( "WebSocket open." );
22
+ writeToLog( "Connected." );
23
+
24
+ $('form').addClass( 'socket-connected' );
25
+ $('#connect').unbind( 'click' ).attr( 'disabled', 'disabled' );
26
+ $('#disconnect').click( doDisconnect ).removeAttr('disabled');
27
+ $('#echo-body').removeAttr('disabled');
28
+ $('#send').click( doSend ).removeAttr('disabled');
29
+ }
30
+
31
+ function onClose( e ) {
32
+ console.debug( "WebSocket closed." );
33
+ writeToLog( "Disconnected." );
34
+
35
+ $('form').removeClass( 'socket-connected' );
36
+ $('#connect').click( doConnect ).removeAttr('disabled');
37
+ $('#disconnect,#echo-body,#send').unbind( 'click' ).attr( 'disabled', 'disabled' );
38
+ }
39
+
40
+ function onMessage( e ) {
41
+ console.debug( "WebSocket message: %s.", e.data );
42
+ writeToLog( "Response: <code>" + e.data + "</code>" );
43
+ }
44
+
45
+ function onError( e ) {
46
+ console.error( "WebSocket error: %o", e );
47
+ writeErrorLog( "WebSocket Error: " + e.data )
48
+ }
49
+
50
+ function doConnect( e ) {
51
+ console.debug( "Connecting WebSocket." );
52
+ writeToLog( "Connecting." );
53
+ var ws_uri = $('meta[name=socket-uri]').attr( 'content' );
54
+ ws_uri = 'ws://' + window.location.host + ws_uri;
55
+
56
+ console.debug( " Socket URI is: %s", ws_uri );
57
+
58
+ ws = new WebSocket( ws_uri, 'echo' );
59
+
60
+ ws.onopen = onOpen;
61
+ ws.onclose = onClose;
62
+ ws.onmessage = onMessage;
63
+ ws.onerror = onError;
64
+ }
65
+
66
+ function doDisconnect( e ) {
67
+ console.debug( "Closing WebSocket." );
68
+ writeToLog( "Disconnecting." );
69
+ ws.close();
70
+ }
71
+
72
+ function doSend( e ) {
73
+ e.preventDefault();
74
+ e.stopPropagation();
75
+
76
+ var data = $('#echo-body').val();
77
+ $('#echo-body').val('');
78
+
79
+ console.debug( "Sending message: %s.", data );
80
+ writeToLog( "Sent: <code>" + data + "</code>." );
81
+
82
+ ws.send( data );
83
+ }
84
+
85
+ $(document).ready( function() {
86
+ log = $('#log');
87
+
88
+ if (window.MozWebSocket) {
89
+ console.debug( 'Using MozWebSocket' );
90
+ window.WebSocket = window.MozWebSocket;
91
+ } else if (!window.WebSocket) {
92
+ console.error( "This browser doesn't support WebSocket. ;_;" );
93
+ return;
94
+ }
95
+
96
+ // Check for recent implementations of the WebSocket API
97
+ if ( typeof WebSocket.CONNECTING == 'undefined' ) {
98
+ console.error( "WebSocket implementation is too old." );
99
+ writeErrorLog( "WebSocket implementation too old. Sorry, you'll need a newer browser." );
100
+ return;
101
+ }
102
+
103
+ $('#connect').click( doConnect );
104
+ $('#disconnect,#echo-body,#send').attr( 'disabled', 'disabled' );
105
+
106
+ writeToLog( "Ready." );
107
+ });
108
+
@@ -0,0 +1,33 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
5
+ <script type="text/javascript" src="/js/websock-test.js"></script>
6
+
7
+ <link rel="stylesheet" href="/css/master.css" type="text/css" media="screen"
8
+ title="no title" charset="utf-8" />
9
+
10
+ <meta name="socket-uri" content="/ws" />
11
+ <meta charset="utf-8" />
12
+
13
+ </head>
14
+ <body class="websocket-test">
15
+ <h1>WebSockets Echo Test</h1>
16
+
17
+ <form action="#" method="get" accept-charset="utf-8">
18
+ <label for="echo-body">Echo message:</label>
19
+ <input type="text" name="echo-body" value="" id="echo-body" disabled="disabled" />
20
+ <button id="send" disabled="disabled">Send</button>
21
+ </form>
22
+
23
+ <section id="connection-controls">
24
+ <button id="connect">Connect</button>
25
+ <button id="disconnect">Disconnect</button>
26
+ </section>
27
+
28
+ <section id="log-box">
29
+ <h2>Log:</h2>
30
+ <ul id="log"></ul>
31
+ </section>
32
+ </body>
33
+ </html>
@@ -6,35 +6,35 @@
6
6
  #
7
7
 
8
8
  # samples server
9
- server '34D8E57C-3E91-4F24-9BBE-0B53C1827CB4' do
9
+ server 'examples' do
10
10
 
11
- name 'main'
12
- default_host 'www.example.com'
11
+ name 'Examples'
12
+ default_host 'localhost'
13
13
 
14
14
  access_log '/logs/access.log'
15
15
  error_log '/logs/error.log'
16
16
  chroot '/var/mongrel2'
17
17
  pid_file '/run/mongrel2.pid'
18
18
 
19
- bind_addr '0.0.0.0'
19
+ bind_addr '127.0.0.1'
20
20
  port 8113
21
21
 
22
22
  # your main host
23
- host 'www.example.com' do
23
+ host 'localhost' do
24
24
 
25
25
  route '/', directory( 'data/mongrel2/', 'bootstrap.html', 'text/html' )
26
26
  route '/source', directory( 'examples/', 'README.txt', 'text/plain' )
27
27
 
28
28
  # Handlers
29
+ dumper = handler( 'tcp://127.0.0.1:9997', 'request-dumper', protocol: 'tnetstring' )
29
30
  route '/hello', handler( 'tcp://127.0.0.1:9999', 'helloworld-handler' )
30
- route '/dump', handler( 'tcp://127.0.0.1:9997', 'request-dumper' )
31
+ route '/dump', dumper
32
+ route '/ws', handler( 'tcp://127.0.0.1:9995', 'ws-echo' )
33
+ route '@js', dumper
34
+ route '<xml', dumper
31
35
 
32
36
  end
33
37
 
34
- filter '/usr/local/lib/mongrel2/filters/null.so',
35
- extensions: ["*.html", "*.txt"],
36
- min_size: 1000
37
-
38
38
  end
39
39
 
40
40
  setting "zeromq.threads", 1