em-eventsource 0.2.3 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +1 -1
  4. data/lib/em-eventsource.rb +17 -2
  5. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 461c9ac878e1f325156439b1d51c298db29fbcc9c23e769fdf0c480baeb83f57
4
- data.tar.gz: 1b9077e69942f41ce43c304116bb7923b66cb398935e3da578b76e03176b60ec
3
+ metadata.gz: f824fba4e073244ab8f97abd68a1e638edee0f5c13f317040f9dc15b64ffe242
4
+ data.tar.gz: 9a560157f4bd6d8445e51b1eec508d63731e5d1c9f5b1be2505bae63ee50ba30
5
5
  SHA512:
6
- metadata.gz: b689983d0970f0f072d1f34ea79c47948b084072ce94b014ef4da1b340cc9c6673a00a1eece3fbe2585e56425090fb7d4186275d6d2f097abafcf1bcacc1e455
7
- data.tar.gz: 65d3b2e2f93416796ec3f958cc9d64253fd24db69c944b5f08aeb6f964efec3715330c9dbc2de3f095273d647358e304465d812c7a1e03918eaa2270c8254ae7
6
+ metadata.gz: b1893a4ca85fab366860240aa015b4b1d7ee3c9dea803420ee4d07c0a195c797699891f7139fa943fbe16fad0aadba570aec684d4ef0408da9e17c2437ed8f83
7
+ data.tar.gz: '0593bf3405f9203efbd32a237edc73b7b07563d1c8df573ab93b53f017c54bc6d5652b56e63343372929c23aaac3b91a63dd2d366f953e080a6b644560032278'
@@ -0,0 +1,13 @@
1
+ # em-eventsource changelog
2
+
3
+ ## 0.3.2
4
+
5
+ - Add TLS hostname verification by default [[#19](https://github.com/francois2metz/em-eventsource/pull/19)]
6
+
7
+ ## 0.3.1
8
+
9
+ - Force UTF-8 encoding on incoming events [[#16](https://github.com/francois2metz/em-eventsource/pull/16)]
10
+
11
+ ## 0.3.0
12
+
13
+ - Handle retry values sent by the server as milliseconds [[#14](https://github.com/francois2metz/em-eventsource/issues/14)]
data/README.md CHANGED
@@ -10,7 +10,7 @@ Install with Rubygems:
10
10
 
11
11
  If you use bundler, add it to your Gemfile:
12
12
 
13
- gem "em-eventsource", "~> 0.2.0"
13
+ gem "em-eventsource", "~> 0.3.0"
14
14
 
15
15
  ## Usage
16
16
 
@@ -35,6 +35,7 @@ module EventMachine
35
35
  # query - the query string as hash
36
36
  # headers - the headers for the request as hash
37
37
  def initialize(url, query={}, headers={})
38
+ @conn = nil
38
39
  @url = url
39
40
  @query = query
40
41
  @headers = headers
@@ -117,6 +118,9 @@ module EventMachine
117
118
  @req.callback(&method(:handle_reconnect))
118
119
  buffer = ""
119
120
  @req.stream do |chunk|
121
+ unless chunk.valid_encoding?
122
+ chunk.scrub!('?')
123
+ end
120
124
  buffer += chunk
121
125
  while index = buffer.index(/\r\n\r\n|\n\n/)
122
126
  stream = buffer.slice!(0..index)
@@ -127,6 +131,13 @@ module EventMachine
127
131
 
128
132
  def handle_reconnect(*args)
129
133
  return if @ready_state == CLOSED
134
+
135
+ if @req.response_header.redirection?
136
+ @url = @req.response_header.location
137
+ listen
138
+ return
139
+ end
140
+
130
141
  @ready_state = CONNECTING
131
142
  @errors.each { |error| error.call("Connection lost. Reconnecting.") }
132
143
  EM.add_timer(@retry) do
@@ -135,6 +146,10 @@ module EventMachine
135
146
  end
136
147
 
137
148
  def handle_headers(headers)
149
+ if headers.redirection?
150
+ @req.close
151
+ return
152
+ end
138
153
  if headers.status != 200
139
154
  close
140
155
  @errors.each { |error| error.call("Unexpected response status #{headers.status}") }
@@ -165,7 +180,7 @@ module EventMachine
165
180
  end
166
181
  /^retry:(.+)$/.match(part) do |m|
167
182
  if m[1].strip! =~ /^[0-9]+$/
168
- @retry = m[1].to_i
183
+ @retry = m[1].to_i / 1000
169
184
  end
170
185
  end
171
186
  end
@@ -179,7 +194,7 @@ module EventMachine
179
194
  end
180
195
 
181
196
  def prepare_request
182
- conn = EM::HttpRequest.new(@url, inactivity_timeout: @inactivity_timeout)
197
+ conn = EM::HttpRequest.new(@url, {tls: {verify_peer: true}, inactivity_timeout: @inactivity_timeout})
183
198
  @middlewares.each do |middleware, block|
184
199
  if block
185
200
  conn.use(*middleware, &block)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-eventsource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - François de Metz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-18 00:00:00.000000000 Z
11
+ date: 2020-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -103,6 +103,7 @@ extensions: []
103
103
  extra_rdoc_files:
104
104
  - README.md
105
105
  files:
106
+ - CHANGELOG.md
106
107
  - Gemfile
107
108
  - README.md
108
109
  - lib/em-eventsource.rb
@@ -124,8 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
125
  - !ruby/object:Gem::Version
125
126
  version: '0'
126
127
  requirements: []
127
- rubyforge_project:
128
- rubygems_version: 2.7.6
128
+ rubygems_version: 3.0.3
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: em-eventsource is an eventmachine library to consume Server-Sent Events streaming