celluloid-eventsource 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +1 -1
- data/lib/celluloid/eventsource/version.rb +1 -1
- data/lib/celluloid/eventsource.rb +5 -2
- data/spec/celluloid/eventsource/response_parser_spec.rb +3 -1
- data/spec/celluloid/eventsource_spec.rb +25 -0
- data/spec/spec_helper.rb +9 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a04973c2d3ee62344eea60784a41fbc3e386d851
|
4
|
+
data.tar.gz: 9ae2e87a728c6a96d18148d9a5cfbac93ea951f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ddf468f93cfb7d72cca9b59b2bfe2dd482671f73db5c8dace8bd9384f9710d6ecb3f9c568a043445816dfbcd1a0d26f6ba84156a346718a319d8202d3b79916
|
7
|
+
data.tar.gz: 0d2eb65594cd71fcc5529b4af985bf9d7483b9b1ed2eee62c9649f85bc9fa60e9dd0f26a925f594e0c56dc8f50f3f3fc252200703890fb4c0b97547b01ddf07b
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -51,7 +51,7 @@ es = Celluloid::EventSource.new("http://example.com/") do |conn|
|
|
51
51
|
end
|
52
52
|
|
53
53
|
conn.on_error do |message|
|
54
|
-
puts "
|
54
|
+
puts "Response status #{message[:status_code]}, Response body #{message[:body]}"
|
55
55
|
end
|
56
56
|
|
57
57
|
conn.on(:time) do |event|
|
@@ -101,8 +101,11 @@ module Celluloid
|
|
101
101
|
end
|
102
102
|
|
103
103
|
if @parser.status_code != 200
|
104
|
+
until @socket.eof?
|
105
|
+
@parser << @socket.readline
|
106
|
+
end
|
104
107
|
close
|
105
|
-
@on[:error].call(
|
108
|
+
@on[:error].call({status_code: @parser.status_code, body: @parser.chunk})
|
106
109
|
end
|
107
110
|
|
108
111
|
handle_headers(@parser.headers)
|
@@ -174,7 +177,7 @@ module Celluloid
|
|
174
177
|
@on[:open].call
|
175
178
|
else
|
176
179
|
close
|
177
|
-
@on[:error].call("Invalid Content-Type #{headers['Content-Type']}. Expected text/event-stream")
|
180
|
+
@on[:error].call({status_code: @parser.status_code, body: "Invalid Content-Type #{headers['Content-Type']}. Expected text/event-stream"})
|
178
181
|
end
|
179
182
|
end
|
180
183
|
|
@@ -9,6 +9,7 @@ Content-Type: text/html; charset=UTF-8
|
|
9
9
|
Content-Length: 131
|
10
10
|
X_CASE_HEADER: foo
|
11
11
|
X_Mixed-Case: bar
|
12
|
+
x-lowcase-header: hello
|
12
13
|
eos
|
13
14
|
}
|
14
15
|
|
@@ -56,7 +57,8 @@ eos
|
|
56
57
|
it 'makes response headers canonicalized' do
|
57
58
|
streamed(response_string) { |line| parser << line }
|
58
59
|
expected_headers = {
|
59
|
-
'X-Mixed-Case' => 'bar', 'Content-Type' => 'text/html; charset=UTF-8', 'Content-Length' => "131",
|
60
|
+
'X-Mixed-Case' => 'bar', 'Content-Type' => 'text/html; charset=UTF-8', 'Content-Length' => "131",
|
61
|
+
'X-Case-Header' => 'foo', 'X-Lowcase-Header' => "hello"
|
60
62
|
}
|
61
63
|
expect(parser.headers).to include(expected_headers)
|
62
64
|
end
|
@@ -78,6 +78,31 @@ RSpec.describe Celluloid::EventSource do
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
+
it 'receives response body through error event' do
|
82
|
+
with_sse_server do |server|
|
83
|
+
expect { |error|
|
84
|
+
ces = Celluloid::EventSource.new("http://localhost:63310/error") do |conn|
|
85
|
+
conn.on_error(&error)
|
86
|
+
end
|
87
|
+
|
88
|
+
sleep TIMEOUT until ces.closed?
|
89
|
+
|
90
|
+
}.to yield_with_args({status_code: 400, body:"blop"})
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'receives response without a body through error event' do
|
95
|
+
with_sse_server do |server|
|
96
|
+
expect { |error|
|
97
|
+
ces = Celluloid::EventSource.new("http://localhost:63310/error/no_body") do |conn|
|
98
|
+
conn.on_error(&error)
|
99
|
+
end
|
100
|
+
|
101
|
+
sleep TIMEOUT until ces.closed?
|
102
|
+
|
103
|
+
}.to yield_with_args({status_code: 400, body:""})
|
104
|
+
end
|
105
|
+
end
|
81
106
|
|
82
107
|
it 'receives custom events through event handlers' do
|
83
108
|
with_sse_server do |server|
|
data/spec/spec_helper.rb
CHANGED
@@ -87,7 +87,15 @@ class ServerSentEvents < Reel::Server::HTTP
|
|
87
87
|
|
88
88
|
def on_connection(connection)
|
89
89
|
connection.each_request do |request|
|
90
|
-
|
90
|
+
if request.path == '/error'
|
91
|
+
request.respond :bad_request, {'Content-Type' => 'application/json; charset=UTF-8'}, "blop"
|
92
|
+
request.close
|
93
|
+
elsif request.path == '/error/no_body'
|
94
|
+
request.respond :bad_request, {'Content-Type' => 'application/json; charset=UTF-8'}
|
95
|
+
request.close
|
96
|
+
else
|
97
|
+
handle_request(request)
|
98
|
+
end
|
91
99
|
end
|
92
100
|
end
|
93
101
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: celluloid-eventsource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leo Correa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid-io
|