em-eventsource 0.2.3 → 0.3.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +1 -1
- data/lib/em-eventsource.rb +17 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f824fba4e073244ab8f97abd68a1e638edee0f5c13f317040f9dc15b64ffe242
|
4
|
+
data.tar.gz: 9a560157f4bd6d8445e51b1eec508d63731e5d1c9f5b1be2505bae63ee50ba30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1893a4ca85fab366860240aa015b4b1d7ee3c9dea803420ee4d07c0a195c797699891f7139fa943fbe16fad0aadba570aec684d4ef0408da9e17c2437ed8f83
|
7
|
+
data.tar.gz: '0593bf3405f9203efbd32a237edc73b7b07563d1c8df573ab93b53f017c54bc6d5652b56e63343372929c23aaac3b91a63dd2d366f953e080a6b644560032278'
|
data/CHANGELOG.md
ADDED
@@ -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
data/lib/em-eventsource.rb
CHANGED
@@ -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
|
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:
|
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
|
-
|
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
|