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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3dbbbc109063bca1fc5bb81a4034ca39438f48f
4
- data.tar.gz: ac911968885e272b5b6e1e3d669e526196a304e3
3
+ metadata.gz: a04973c2d3ee62344eea60784a41fbc3e386d851
4
+ data.tar.gz: 9ae2e87a728c6a96d18148d9a5cfbac93ea951f4
5
5
  SHA512:
6
- metadata.gz: 12975ec688913ea7370198f848b910bfc2f5290c370714cf39303122c6ee1a7fbb9095a689306273be2f56098d20a05a3423531a6cc5fb02c56437de30e8b67a
7
- data.tar.gz: 067be06d38ce78d5c95e8105031363cbfa206d3efec7f72aeab245de75baaaa8a6fe41b9dec915501b567af63f9d28638d58806552ee0631dedc6c0c4561c3d5
6
+ metadata.gz: 8ddf468f93cfb7d72cca9b59b2bfe2dd482671f73db5c8dace8bd9384f9710d6ecb3f9c568a043445816dfbcd1a0d26f6ba84156a346718a319d8202d3b79916
7
+ data.tar.gz: 0d2eb65594cd71fcc5529b4af985bf9d7483b9b1ed2eee62c9649f85bc9fa60e9dd0f26a925f594e0c56dc8f50f3f3fc252200703890fb4c0b97547b01ddf07b
data/.gitignore CHANGED
@@ -5,6 +5,7 @@
5
5
  .yardoc
6
6
  .ruby-version
7
7
  .ruby-gemset
8
+ examples/
8
9
  Gemfile.lock
9
10
  InstalledFiles
10
11
  _yardoc
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 "Error message #{message}"
54
+ puts "Response status #{message[:status_code]}, Response body #{message[:body]}"
55
55
  end
56
56
 
57
57
  conn.on(:time) do |event|
@@ -1,5 +1,5 @@
1
1
  module Celluloid
2
2
  class EventSource
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -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("Unable to establish connection. Response status #{@parser.status_code}")
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", 'X-Case-Header' => 'foo'
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
- handle_request(request)
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.1.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-07-14 00:00:00.000000000 Z
11
+ date: 2014-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid-io