faye 0.7.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of faye might be problematic. Click here for more details.
- data/History.txt +15 -3
- data/README.rdoc +2 -6
- data/lib/faye-browser-min.js +1 -1
- data/lib/faye.rb +25 -36
- data/lib/faye/adapters/rack_adapter.rb +43 -22
- data/lib/faye/engines/connection.rb +7 -10
- data/lib/faye/engines/memory.rb +28 -28
- data/lib/faye/engines/proxy.rb +109 -0
- data/lib/faye/mixins/logging.rb +1 -8
- data/lib/faye/mixins/timeouts.rb +1 -1
- data/lib/faye/protocol/channel.rb +3 -3
- data/lib/faye/protocol/client.rb +50 -45
- data/lib/faye/protocol/extensible.rb +11 -18
- data/lib/faye/protocol/server.rb +53 -38
- data/lib/faye/transport/http.rb +49 -27
- data/lib/faye/transport/transport.rb +3 -1
- data/lib/faye/transport/web_socket.rb +6 -10
- data/lib/faye/util/namespace.rb +2 -2
- data/spec/browser.html +3 -1
- data/spec/encoding_helper.rb +7 -0
- data/spec/javascript/client_spec.js +0 -5
- data/spec/javascript/engine/memory_spec.js +7 -0
- data/spec/javascript/engine_spec.js +22 -57
- data/spec/javascript/server/handshake_spec.js +10 -6
- data/spec/javascript/server/integration_spec.js +11 -10
- data/spec/javascript/server/publish_spec.js +85 -0
- data/spec/javascript/server_spec.js +5 -51
- data/spec/node.js +6 -6
- data/spec/ruby/client_spec.rb +1 -1
- data/spec/ruby/engine/memory_spec.rb +7 -0
- data/spec/ruby/{engine_spec.rb → engine_examples.rb} +28 -34
- data/spec/ruby/rack_adapter_spec.rb +1 -1
- data/spec/ruby/server/handshake_spec.rb +10 -6
- data/spec/ruby/server/publish_spec.rb +81 -0
- data/spec/ruby/server_spec.rb +6 -44
- data/spec/spec_helper.rb +5 -18
- data/spec/testswarm +1 -5
- metadata +105 -180
- data/lib/faye/engines/base.rb +0 -66
- data/lib/faye/engines/redis.rb +0 -225
- data/lib/faye/thin_extensions.rb +0 -75
- data/lib/faye/util/web_socket.rb +0 -89
- data/lib/faye/util/web_socket/api.rb +0 -103
- data/lib/faye/util/web_socket/client.rb +0 -82
- data/lib/faye/util/web_socket/draft75_parser.rb +0 -53
- data/lib/faye/util/web_socket/draft76_parser.rb +0 -53
- data/lib/faye/util/web_socket/protocol8_parser.rb +0 -324
- data/spec/javascript/web_socket/client_spec.js +0 -121
- data/spec/javascript/web_socket/draft75parser_spec.js +0 -39
- data/spec/javascript/web_socket/protocol8parser_spec.js +0 -153
- data/spec/redis.conf +0 -42
- data/spec/ruby/web_socket/client_spec.rb +0 -126
- data/spec/ruby/web_socket/draft75_parser_spec.rb +0 -41
- data/spec/ruby/web_socket/protocol8_parser_spec.rb +0 -145
| @@ -1,41 +0,0 @@ | |
| 1 | 
            -
            # encoding=utf-8
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            require "spec_helper"
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            describe Faye::WebSocket::Draft75Parser do
         | 
| 6 | 
            -
              include EncodingHelper
         | 
| 7 | 
            -
              
         | 
| 8 | 
            -
              before do
         | 
| 9 | 
            -
                @web_socket = mock Faye::WebSocket
         | 
| 10 | 
            -
                @parser = Faye::WebSocket::Draft75Parser.new(@web_socket)
         | 
| 11 | 
            -
              end
         | 
| 12 | 
            -
              
         | 
| 13 | 
            -
              describe :parse do
         | 
| 14 | 
            -
                it "parses text frames" do
         | 
| 15 | 
            -
                  @web_socket.should_receive(:receive).with("Hello")
         | 
| 16 | 
            -
                  parse [0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0xff]
         | 
| 17 | 
            -
                end
         | 
| 18 | 
            -
                
         | 
| 19 | 
            -
                it "parses multibyte text frames" do
         | 
| 20 | 
            -
                  @web_socket.should_receive(:receive).with(encode "Apple = ")
         | 
| 21 | 
            -
                  parse [0x00, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0xef, 0xa3, 0xbf, 0xff]
         | 
| 22 | 
            -
                end
         | 
| 23 | 
            -
                
         | 
| 24 | 
            -
                it "parses fragmented frames" do
         | 
| 25 | 
            -
                  @web_socket.should_receive(:receive).with("Hello")
         | 
| 26 | 
            -
                  parse [0x00, 0x48, 0x65, 0x6c]
         | 
| 27 | 
            -
                  parse [0x6c, 0x6f, 0xff]
         | 
| 28 | 
            -
                end
         | 
| 29 | 
            -
              end
         | 
| 30 | 
            -
              
         | 
| 31 | 
            -
              describe :frame do
         | 
| 32 | 
            -
                it "returns the given string formatted as a WebSocket frame" do
         | 
| 33 | 
            -
                  bytes(@parser.frame "Hello").should == [0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0xff]
         | 
| 34 | 
            -
                end
         | 
| 35 | 
            -
                
         | 
| 36 | 
            -
                it "encodes multibyte characters correctly" do
         | 
| 37 | 
            -
                  message = encode "Apple = "
         | 
| 38 | 
            -
                  bytes(@parser.frame message).should == [0x00, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0xef, 0xa3, 0xbf, 0xff]
         | 
| 39 | 
            -
                end
         | 
| 40 | 
            -
              end
         | 
| 41 | 
            -
            end
         | 
| @@ -1,145 +0,0 @@ | |
| 1 | 
            -
            # encoding=utf-8
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            require "spec_helper"
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            describe Faye::WebSocket::Protocol8Parser do
         | 
| 6 | 
            -
              include EncodingHelper
         | 
| 7 | 
            -
              
         | 
| 8 | 
            -
              before do
         | 
| 9 | 
            -
                @web_socket = mock Faye::WebSocket
         | 
| 10 | 
            -
                @parser = Faye::WebSocket::Protocol8Parser.new(@web_socket)
         | 
| 11 | 
            -
              end
         | 
| 12 | 
            -
              
         | 
| 13 | 
            -
              describe :parse do
         | 
| 14 | 
            -
                let(:mask) { (1..4).map { rand 255 } }
         | 
| 15 | 
            -
                
         | 
| 16 | 
            -
                def mask_message(*bytes)
         | 
| 17 | 
            -
                  output = []
         | 
| 18 | 
            -
                  bytes.each_with_index do |byte, i|
         | 
| 19 | 
            -
                    output[i] = byte ^ mask[i % 4]
         | 
| 20 | 
            -
                  end
         | 
| 21 | 
            -
                  output
         | 
| 22 | 
            -
                end
         | 
| 23 | 
            -
                
         | 
| 24 | 
            -
                it "parses unmasked text frames" do
         | 
| 25 | 
            -
                  @web_socket.should_receive(:receive).with("Hello")
         | 
| 26 | 
            -
                  parse [0x81, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f]
         | 
| 27 | 
            -
                end
         | 
| 28 | 
            -
                
         | 
| 29 | 
            -
                it "parses empty text frames" do
         | 
| 30 | 
            -
                  @web_socket.should_receive(:receive).with("")
         | 
| 31 | 
            -
                  parse [0x81, 0x00]
         | 
| 32 | 
            -
                end
         | 
| 33 | 
            -
                
         | 
| 34 | 
            -
                it "parses fragmented text frames" do
         | 
| 35 | 
            -
                  @web_socket.should_receive(:receive).with("Hello")
         | 
| 36 | 
            -
                  parse [0x01, 0x03, 0x48, 0x65, 0x6c]
         | 
| 37 | 
            -
                  parse [0x80, 0x02, 0x6c, 0x6f]
         | 
| 38 | 
            -
                end
         | 
| 39 | 
            -
                
         | 
| 40 | 
            -
                it "parses masked text frames" do
         | 
| 41 | 
            -
                  @web_socket.should_receive(:receive).with("Hello")
         | 
| 42 | 
            -
                  parse [0x81, 0x85] + mask + mask_message(0x48, 0x65, 0x6c, 0x6c, 0x6f)
         | 
| 43 | 
            -
                end
         | 
| 44 | 
            -
                
         | 
| 45 | 
            -
                it "parses masked empty text frames" do
         | 
| 46 | 
            -
                  @web_socket.should_receive(:receive).with("")
         | 
| 47 | 
            -
                  parse [0x81, 0x80] + mask + mask_message()
         | 
| 48 | 
            -
                end
         | 
| 49 | 
            -
                
         | 
| 50 | 
            -
                it "parses masked fragmented text frames" do
         | 
| 51 | 
            -
                  @web_socket.should_receive(:receive).with("Hello")
         | 
| 52 | 
            -
                  parse [0x01, 0x81] + mask + mask_message(0x48)
         | 
| 53 | 
            -
                  parse [0x80, 0x84] + mask + mask_message(0x65, 0x6c, 0x6c, 0x6f)
         | 
| 54 | 
            -
                end
         | 
| 55 | 
            -
                
         | 
| 56 | 
            -
                it "closes the socket if the frame has an unrecognized opcode" do
         | 
| 57 | 
            -
                  @web_socket.should_receive(:close).with(1002, nil, false)
         | 
| 58 | 
            -
                  parse [0x83, 0x00]
         | 
| 59 | 
            -
                end
         | 
| 60 | 
            -
                
         | 
| 61 | 
            -
                it "closes the socket if a close frame is received" do
         | 
| 62 | 
            -
                  @web_socket.should_receive(:close).with(1000, "Hello", false)
         | 
| 63 | 
            -
                  parse [0x88, 0x07, 0x03, 0xe8, 0x48, 0x65, 0x6c, 0x6c, 0x6f]
         | 
| 64 | 
            -
                end
         | 
| 65 | 
            -
                
         | 
| 66 | 
            -
                it "parses unmasked multibyte text frames" do
         | 
| 67 | 
            -
                  @web_socket.should_receive(:receive).with(encode "Apple = ")
         | 
| 68 | 
            -
                  parse [0x81, 0x0b, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0xef, 0xa3, 0xbf]
         | 
| 69 | 
            -
                end
         | 
| 70 | 
            -
                
         | 
| 71 | 
            -
                it "parses fragmented multibyte text frames" do
         | 
| 72 | 
            -
                  @web_socket.should_receive(:receive).with(encode "Apple = ")
         | 
| 73 | 
            -
                  parse [0x01, 0x0a, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0xef, 0xa3]
         | 
| 74 | 
            -
                  parse [0x80, 0x01, 0xbf]
         | 
| 75 | 
            -
                end
         | 
| 76 | 
            -
                
         | 
| 77 | 
            -
                it "parses masked multibyte text frames" do
         | 
| 78 | 
            -
                  @web_socket.should_receive(:receive).with(encode "Apple = ")
         | 
| 79 | 
            -
                  parse [0x81, 0x8b] + mask + mask_message(0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0xef, 0xa3, 0xbf)
         | 
| 80 | 
            -
                end
         | 
| 81 | 
            -
                
         | 
| 82 | 
            -
                it "parses masked fragmented multibyte text frames" do
         | 
| 83 | 
            -
                  @web_socket.should_receive(:receive).with(encode "Apple = ")
         | 
| 84 | 
            -
                  parse [0x01, 0x8a] + mask + mask_message(0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0xef, 0xa3)
         | 
| 85 | 
            -
                  parse [0x80, 0x81] + mask + mask_message(0xbf)
         | 
| 86 | 
            -
                end
         | 
| 87 | 
            -
                
         | 
| 88 | 
            -
                it "parses unmasked medium-length text frames" do
         | 
| 89 | 
            -
                  @web_socket.should_receive(:receive).with("Hello" * 40)
         | 
| 90 | 
            -
                  parse [0x81, 0x7e, 0x00, 0xc8] + [0x48, 0x65, 0x6c, 0x6c, 0x6f] * 40
         | 
| 91 | 
            -
                end
         | 
| 92 | 
            -
                
         | 
| 93 | 
            -
                it "parses masked medium-length text frames" do
         | 
| 94 | 
            -
                  @web_socket.should_receive(:receive).with("Hello" * 40)
         | 
| 95 | 
            -
                  parse [0x81, 0xfe, 0x00, 0xc8] + mask + mask_message(*([0x48, 0x65, 0x6c, 0x6c, 0x6f] * 40))
         | 
| 96 | 
            -
                end
         | 
| 97 | 
            -
                
         | 
| 98 | 
            -
                it "replies to pings with a pong" do
         | 
| 99 | 
            -
                  @web_socket.should_receive(:send).with([0x4f, 0x48, 0x41, 0x49], :pong)
         | 
| 100 | 
            -
                  parse [0x89, 0x04, 0x4f, 0x48, 0x41, 0x49]
         | 
| 101 | 
            -
                end
         | 
| 102 | 
            -
              end
         | 
| 103 | 
            -
              
         | 
| 104 | 
            -
              describe :frame do
         | 
| 105 | 
            -
                it "returns the given string formatted as a WebSocket frame" do
         | 
| 106 | 
            -
                  bytes(@parser.frame "Hello").should == [0x81, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f]
         | 
| 107 | 
            -
                end
         | 
| 108 | 
            -
                
         | 
| 109 | 
            -
                it "encodes multibyte characters correctly" do
         | 
| 110 | 
            -
                  message = encode "Apple = "
         | 
| 111 | 
            -
                  bytes(@parser.frame message).should == [0x81, 0x0b, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0xef, 0xa3, 0xbf]
         | 
| 112 | 
            -
                end
         | 
| 113 | 
            -
                
         | 
| 114 | 
            -
                it "encodes medium-length strings using extra length bytes" do
         | 
| 115 | 
            -
                  message = "Hello" * 40
         | 
| 116 | 
            -
                  bytes(@parser.frame message).should == [0x81, 0x7e, 0x00, 0xc8] + [0x48, 0x65, 0x6c, 0x6c, 0x6f] * 40
         | 
| 117 | 
            -
                end
         | 
| 118 | 
            -
                
         | 
| 119 | 
            -
                it "encodes long strings using extra length bytes" do
         | 
| 120 | 
            -
                  message = "Hello" * 13108
         | 
| 121 | 
            -
                  bytes(@parser.frame message).should == [0x81, 0x7f] +
         | 
| 122 | 
            -
                                                         [0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04] +
         | 
| 123 | 
            -
                                                         [0x48, 0x65, 0x6c, 0x6c, 0x6f] * 13108
         | 
| 124 | 
            -
                end
         | 
| 125 | 
            -
                
         | 
| 126 | 
            -
                it "encodes close frames with an error code" do
         | 
| 127 | 
            -
                  frame = @parser.frame "Hello", :close, 1002
         | 
| 128 | 
            -
                  bytes(frame).should == [0x88, 0x07, 0x03, 0xea, 0x48, 0x65, 0x6c, 0x6c, 0x6f]
         | 
| 129 | 
            -
                end
         | 
| 130 | 
            -
                
         | 
| 131 | 
            -
                it "encodes pong frames" do
         | 
| 132 | 
            -
                  bytes(@parser.frame '', :pong).should == [0x8a, 0x00]
         | 
| 133 | 
            -
                end
         | 
| 134 | 
            -
              end
         | 
| 135 | 
            -
              
         | 
| 136 | 
            -
              describe :utf8 do
         | 
| 137 | 
            -
                it "detects valid UTF-8" do
         | 
| 138 | 
            -
                  Faye.valid_utf8?( [72, 101, 108, 108, 111, 45, 194, 181, 64, 195, 159, 195, 182, 195, 164, 195, 188, 195, 160, 195, 161, 45, 85, 84, 70, 45, 56, 33, 33] ).should be_true
         | 
| 139 | 
            -
                end
         | 
| 140 | 
            -
                
         | 
| 141 | 
            -
                it "detects invalid UTF-8" do
         | 
| 142 | 
            -
                  Faye.valid_utf8?( [206, 186, 225, 189, 185, 207, 131, 206, 188, 206, 181, 237, 160, 128, 101, 100, 105, 116, 101, 100] ).should be_false
         | 
| 143 | 
            -
                end
         | 
| 144 | 
            -
              end
         | 
| 145 | 
            -
            end
         |