faye 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of faye might be problematic. Click here for more details.

@@ -13,7 +13,7 @@ require 'uri'
13
13
  require 'yajl'
14
14
 
15
15
  module Faye
16
- VERSION = '0.8.1'
16
+ VERSION = '0.8.2'
17
17
 
18
18
  ROOT = File.expand_path(File.dirname(__FILE__))
19
19
 
@@ -37,6 +37,7 @@ module Faye
37
37
  autoload :Error, File.join(ROOT, 'faye', 'error')
38
38
 
39
39
  autoload :RackAdapter, File.join(ROOT, 'faye', 'adapters', 'rack_adapter')
40
+ autoload :StaticServer, File.join(ROOT, 'faye', 'adapters', 'static_server')
40
41
 
41
42
  BAYEUX_VERSION = '1.0'
42
43
  JSONP_CALLBACK = 'jsonpcallback'
@@ -9,7 +9,7 @@ module Faye
9
9
  ASYNC_RESPONSE = [-1, {}, []].freeze
10
10
 
11
11
  DEFAULT_ENDPOINT = '/bayeux'
12
- SCRIPT_PATH = File.join(ROOT, 'faye-browser-min.js')
12
+ SCRIPT_PATH = 'faye-browser-min.js'
13
13
 
14
14
  TYPE_JSON = {'Content-Type' => 'application/json'}
15
15
  TYPE_SCRIPT = {'Content-Type' => 'text/javascript'}
@@ -25,9 +25,13 @@ module Faye
25
25
  @options = [app, options].grep(Hash).first || {}
26
26
 
27
27
  @endpoint = @options[:mount] || DEFAULT_ENDPOINT
28
- @endpoint_re = Regexp.new('^' + @endpoint + '(/[^/]*)*(\\.js)?$')
28
+ @endpoint_re = Regexp.new('^' + @endpoint + '(/[^/]+)*(\\.[^\\.]+)?$')
29
29
  @server = Server.new(@options)
30
30
 
31
+ @static = StaticServer.new(ROOT, /\.(?:js|map)$/)
32
+ @static.map(File.basename(@endpoint) + '.js', SCRIPT_PATH)
33
+ @static.map('client.js', SCRIPT_PATH)
34
+
31
35
  return unless extensions = @options[:extensions]
32
36
  [*extensions].each { |extension| add_extension(extension) }
33
37
  end
@@ -75,8 +79,12 @@ module Faye
75
79
  [404, TYPE_TEXT, ["Sure you're not looking for #{@endpoint} ?"]]
76
80
  end
77
81
 
78
- return serve_client_script(env) if request.path_info =~ /\.js$/
79
- return handle_options(request) if env['REQUEST_METHOD'] == 'OPTIONS'
82
+ # http://groups.google.com/group/faye-users/browse_thread/thread/4a01bb7d25d3636a
83
+ if env['REQUEST_METHOD'] == 'OPTIONS' or env['HTTP_ACCESS_CONTROL_REQUEST_METHOD'] == 'POST'
84
+ return handle_options(request)
85
+ end
86
+
87
+ return @static.call(env) if @static =~ request.path_info
80
88
  return handle_websocket(env) if Faye::WebSocket.websocket?(env)
81
89
  return handle_eventsource(env) if Faye::EventSource.eventsource?(env)
82
90
 
@@ -85,27 +93,6 @@ module Faye
85
93
 
86
94
  private
87
95
 
88
- def serve_client_script(env)
89
- @client_script ||= File.read(SCRIPT_PATH)
90
- @client_digest ||= Digest::SHA1.hexdigest(@client_script)
91
- @client_mtime ||= File.mtime(SCRIPT_PATH)
92
-
93
- headers = TYPE_SCRIPT.dup
94
- ims = env['HTTP_IF_MODIFIED_SINCE']
95
-
96
- headers['Content-Length'] = @client_script.bytesize.to_s unless env[HTTP_X_NO_CONTENT_LENGTH]
97
- headers['ETag'] = @client_digest
98
- headers['Last-Modified'] = @client_mtime.httpdate
99
-
100
- if env['HTTP_IF_NONE_MATCH'] == @client_digest
101
- [304, headers, ['']]
102
- elsif ims and @client_mtime <= Time.httpdate(ims)
103
- [304, headers, ['']]
104
- else
105
- [200, headers, [@client_script]]
106
- end
107
- end
108
-
109
96
  def handle_request(request)
110
97
  json_msg = message_from_request(request)
111
98
  message = Yajl::Parser.parse(json_msg)
@@ -0,0 +1,56 @@
1
+ module Faye
2
+ class StaticServer
3
+
4
+ def initialize(directory, path_regex)
5
+ @directory = directory
6
+ @path_regex = path_regex
7
+ @path_map = {}
8
+ @index = {}
9
+ end
10
+
11
+ def map(request_path, filename)
12
+ @path_map[request_path] = filename
13
+ end
14
+
15
+ def =~(pathname)
16
+ @path_regex =~ pathname
17
+ end
18
+
19
+ def call(env)
20
+ pathname = env['PATH_INFO']
21
+ pathname = File.basename(pathname)
22
+ pathname = @path_map[pathname] || pathname
23
+
24
+ cache = @index[pathname] ||= {}
25
+ fullpath = File.join(@directory, pathname)
26
+
27
+ begin
28
+ cache[:content] ||= File.read(fullpath)
29
+ cache[:digest] ||= Digest::SHA1.hexdigest(cache[:content])
30
+ cache[:mtime] ||= File.mtime(fullpath)
31
+ rescue
32
+ return [404, {}, []]
33
+ end
34
+
35
+ type = /\.js$/ =~ fullpath ? RackAdapter::TYPE_SCRIPT : RackAdapter::TYPE_JSON
36
+ headers = type.dup
37
+ ims = env['HTTP_IF_MODIFIED_SINCE']
38
+
39
+ no_content_length = env[RackAdapter::HTTP_X_NO_CONTENT_LENGTH]
40
+
41
+ headers['Content-Length'] = '0' unless no_content_length
42
+ headers['ETag'] = cache[:digest]
43
+ headers['Last-Modified'] = cache[:mtime].httpdate
44
+
45
+ if env['HTTP_IF_NONE_MATCH'] == cache[:digest]
46
+ [304, headers, ['']]
47
+ elsif ims and cache[:mtime] <= Time.httpdate(ims)
48
+ [304, headers, ['']]
49
+ else
50
+ headers['Content-Length'] = cache[:content].bytesize.to_s unless no_content_length
51
+ [200, headers, [cache[:content]]]
52
+ end
53
+ end
54
+
55
+ end
56
+ end
@@ -19,7 +19,7 @@
19
19
  JS.cacheBust = true
20
20
 
21
21
  JS.Packages(function() { with(this) {
22
- file('../build/faye-browser-min.js').provides('Faye')
22
+ file('../build/browser/faye-browser-min.js').provides('Faye')
23
23
  autoload(/.*Spec/, {from: './javascript'})
24
24
  }})
25
25
 
@@ -243,7 +243,7 @@ JS.ENV.EngineSpec = JS.Test.describe("Pub/sub engines", function() { with(this)
243
243
 
244
244
  describe("publish", function() { with(this) {
245
245
  before(function() { with(this) {
246
- this.message = {"channel": "/messages/foo", "data": "ok"}
246
+ this.message = {"channel": "/messages/foo", "data": "ok", "blank": null}
247
247
  connect("alice", engine)
248
248
  connect("bob", engine)
249
249
  connect("carol", engine)
@@ -12,4 +12,23 @@ JS.ENV.FayeSpec = JS.Test.describe("Faye", function() { with(this) {
12
12
  assertEqual( expected, ids )
13
13
  }})
14
14
  }})
15
+
16
+ describe("copyObject", function() { with(this) {
17
+ before(function() { with(this) {
18
+ this.object = {foo: "bar", qux: 42, hey: null, obj: {bar: 67}}
19
+ }})
20
+
21
+ it("returns an equal object", function() { with(this) {
22
+ assertEqual( {foo: "bar", qux: 42, hey: null, obj: {bar: 67}},
23
+ Faye.copyObject(object) )
24
+ }})
25
+
26
+ it("does not return the same object", function() { with(this) {
27
+ assertNotSame( object, Faye.copyObject(object) )
28
+ }})
29
+
30
+ it("performs a deep clone", function() { with(this) {
31
+ assertNotSame( object.obj, Faye.copyObject(object).obj )
32
+ }})
33
+ }})
15
34
  }})
@@ -66,8 +66,8 @@ JS.ENV.Server.IntegrationSpec = JS.Test.describe("Server integration", function(
66
66
  after(function() { this.stop() })
67
67
 
68
68
  it("delivers a message between clients", function() { with(this) {
69
- publish("alice", "/foo", {hello: "world"})
70
- check_inbox("bob", "/foo", [{hello: "world"}])
69
+ publish("alice", "/foo", {hello: "world", extra: null})
70
+ check_inbox("bob", "/foo", [{hello: "world", extra: null}])
71
71
  }})
72
72
 
73
73
  it("does not deliver messages for unsubscribed channels", function() { with(this) {
@@ -1,5 +1,5 @@
1
1
  require('jsclass')
2
- Faye = require('../build/faye-node')
2
+ Faye = require('../build/node/faye-node')
3
3
  Faye.logger = function() {}
4
4
 
5
5
  JS.Packages(function() { with(this) {
@@ -253,7 +253,7 @@ describe "Pub/sub engines" do
253
253
 
254
254
  describe :publish do
255
255
  before do
256
- @message = {"channel" => "/messages/foo", "data" => "ok"}
256
+ @message = {"channel" => "/messages/foo", "data" => "ok", "blank" => nil}
257
257
  connect :alice, engine
258
258
  connect :bob, engine
259
259
  connect :carol, engine
@@ -11,4 +11,20 @@ describe Faye do
11
11
  ids.should be_all { |id| id.size == 25 }
12
12
  end
13
13
  end
14
+
15
+ describe :copy_obect do
16
+ let(:object) { {"foo" => "bar", "qux" => 42, "hey" => nil, "obj" => {"bar" => 67}} }
17
+
18
+ it "returns an equal object" do
19
+ Faye.copy_object(object).should == {"foo" => "bar", "qux" => 42, "hey" => nil, "obj" => {"bar" => 67}}
20
+ end
21
+
22
+ it "does not return the same object" do
23
+ Faye.copy_object(object).should_not be_equal(object)
24
+ end
25
+
26
+ it "performs a deep clone" do
27
+ Faye.copy_object(object)["obj"].should_not be_equal(object["obj"])
28
+ end
29
+ end
14
30
  end
@@ -75,8 +75,8 @@ describe "server integration" do
75
75
 
76
76
  shared_examples_for "message bus" do
77
77
  it "delivers a message between clients" do
78
- publish :alice, "/foo", {"hello" => "world"}
79
- check_inbox :bob, "/foo", [{"hello" => "world"}]
78
+ publish :alice, "/foo", {"hello" => "world", "extra" => nil}
79
+ check_inbox :bob, "/foo", [{"hello" => "world", "extra" => nil}]
80
80
  end
81
81
 
82
82
  it "does not deliver messages for unsubscribed channels" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faye
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-15 00:00:00.000000000 Z
12
+ date: 2012-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cookiejar
16
- requirement: &15064400 !ruby/object:Gem::Requirement
16
+ requirement: &8179160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.3.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *15064400
24
+ version_requirements: *8179160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: em-http-request
27
- requirement: &15063780 !ruby/object:Gem::Requirement
27
+ requirement: &8196520 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.3.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *15063780
35
+ version_requirements: *8196520
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: eventmachine
38
- requirement: &15063320 !ruby/object:Gem::Requirement
38
+ requirement: &8196060 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.12.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *15063320
46
+ version_requirements: *8196060
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: faye-websocket
49
- requirement: &15062820 !ruby/object:Gem::Requirement
49
+ requirement: &8195500 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.4.0
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *15062820
57
+ version_requirements: *8195500
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rack
60
- requirement: &15062340 !ruby/object:Gem::Requirement
60
+ requirement: &8195000 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.0.0
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *15062340
68
+ version_requirements: *8195000
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yajl-ruby
71
- requirement: &15061860 !ruby/object:Gem::Requirement
71
+ requirement: &8194260 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.0.0
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *15061860
79
+ version_requirements: *8194260
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: compass
82
- requirement: &15061380 !ruby/object:Gem::Requirement
82
+ requirement: &8192940 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,21 +87,21 @@ dependencies:
87
87
  version: 0.10.0
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *15061380
90
+ version_requirements: *8192940
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: jake
93
- requirement: &15061000 !ruby/object:Gem::Requirement
93
+ requirement: &8192460 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
97
97
  - !ruby/object:Gem::Version
98
- version: '0'
98
+ version: 1.1.1
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *15061000
101
+ version_requirements: *8192460
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rake
104
- requirement: &15060540 !ruby/object:Gem::Requirement
104
+ requirement: &8192020 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *15060540
112
+ version_requirements: *8192020
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: rspec
115
- requirement: &15060040 !ruby/object:Gem::Requirement
115
+ requirement: &8191400 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 2.8.0
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *15060040
123
+ version_requirements: *8191400
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: rack-proxy
126
- requirement: &15059600 !ruby/object:Gem::Requirement
126
+ requirement: &8190920 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *15059600
134
+ version_requirements: *8190920
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: rack-test
137
- requirement: &15059140 !ruby/object:Gem::Requirement
137
+ requirement: &8190460 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *15059140
145
+ version_requirements: *8190460
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: rainbows
148
- requirement: &15058620 !ruby/object:Gem::Requirement
148
+ requirement: &8189960 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,10 +153,10 @@ dependencies:
153
153
  version: 1.0.0
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *15058620
156
+ version_requirements: *8189960
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: RedCloth
159
- requirement: &15058000 !ruby/object:Gem::Requirement
159
+ requirement: &8189420 !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
162
162
  - - ~>
@@ -164,10 +164,10 @@ dependencies:
164
164
  version: 3.0.0
165
165
  type: :development
166
166
  prerelease: false
167
- version_requirements: *15058000
167
+ version_requirements: *8189420
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: sinatra
170
- requirement: &15057460 !ruby/object:Gem::Requirement
170
+ requirement: &8209100 !ruby/object:Gem::Requirement
171
171
  none: false
172
172
  requirements:
173
173
  - - ! '>='
@@ -175,10 +175,10 @@ dependencies:
175
175
  version: '0'
176
176
  type: :development
177
177
  prerelease: false
178
- version_requirements: *15057460
178
+ version_requirements: *8209100
179
179
  - !ruby/object:Gem::Dependency
180
180
  name: staticmatic
181
- requirement: &15073620 !ruby/object:Gem::Requirement
181
+ requirement: &8207860 !ruby/object:Gem::Requirement
182
182
  none: false
183
183
  requirements:
184
184
  - - ! '>='
@@ -186,10 +186,10 @@ dependencies:
186
186
  version: '0'
187
187
  type: :development
188
188
  prerelease: false
189
- version_requirements: *15073620
189
+ version_requirements: *8207860
190
190
  - !ruby/object:Gem::Dependency
191
191
  name: thin
192
- requirement: &15073100 !ruby/object:Gem::Requirement
192
+ requirement: &8206760 !ruby/object:Gem::Requirement
193
193
  none: false
194
194
  requirements:
195
195
  - - ! '>='
@@ -197,7 +197,7 @@ dependencies:
197
197
  version: 1.2.0
198
198
  type: :development
199
199
  prerelease: false
200
- version_requirements: *15073100
200
+ version_requirements: *8206760
201
201
  description:
202
202
  email: jcoglan@gmail.com
203
203
  executables: []
@@ -207,7 +207,9 @@ extra_rdoc_files:
207
207
  files:
208
208
  - History.txt
209
209
  - README.rdoc
210
+ - lib/faye-browser.js
210
211
  - lib/faye-browser-min.js
212
+ - lib/faye-browser-min.js.map
211
213
  - spec/browser.html
212
214
  - spec/phantom.js
213
215
  - spec/install.sh
@@ -269,6 +271,7 @@ files:
269
271
  - lib/faye/protocol/channel.rb
270
272
  - lib/faye/protocol/grammar.rb
271
273
  - lib/faye/adapters/rack_adapter.rb
274
+ - lib/faye/adapters/static_server.rb
272
275
  - lib/faye/engines/proxy.rb
273
276
  - lib/faye/engines/connection.rb
274
277
  - lib/faye/engines/memory.rb