ld-eventsource 2.2.0 → 2.2.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/README.md +1 -1
- data/lib/ld-eventsource/client.rb +10 -10
- data/lib/ld-eventsource/impl/event_parser.rb +14 -8
- data/lib/ld-eventsource/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 218cc36d5dda460be0004eb338d39d5ebeeeed75c5d12150bc8374c1fcc59ebf
|
4
|
+
data.tar.gz: f5da16ee1ae0277e069b6f94f5ff133dd119cb247196b810bf517fb3831a8118
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eee2596eb7bb33f476b969a03908a414705fbcc237afa246d2e6057933ac3ccb56aa4416f810ead64cc1b1ff33bcc326798a2d703cc96bdd2c270bcc1a0fccde
|
7
|
+
data.tar.gz: ce9da2a43a93d3eba73eafdce1070c4f049dc99fc7522c28c7fbb4f37b5a8ab0ca3f4a7866c66c29c739f5056b192fb08aad87a22e242e92cda9679c89281d28
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
LaunchDarkly SSE Client for Ruby
|
2
2
|
================================
|
3
3
|
|
4
|
-
[](http://badge.fury.io/rb/ld-eventsource) [](http://badge.fury.io/rb/ld-eventsource) [](https://circleci.com/gh/launchdarkly/ruby-eventsource/tree/main)
|
5
5
|
|
6
6
|
A client for the [Server-Sent Events](https://www.w3.org/TR/eventsource/) protocol. This implementation runs on a worker thread, and uses the [`http`](https://rubygems.org/gems/http) gem to manage a persistent connection. Its primary purpose is to support the [LaunchDarkly SDK for Ruby](https://github.com/launchdarkly/ruby-client), but it can be used independently.
|
7
7
|
|
@@ -85,7 +85,7 @@ module SSE
|
|
85
85
|
# if you want to use something other than the default `TCPSocket`; it must implement
|
86
86
|
# `open(uri, timeout)` to return a connected `Socket`
|
87
87
|
# @yieldparam [Client] client the new client instance, before opening the connection
|
88
|
-
#
|
88
|
+
#
|
89
89
|
def initialize(uri,
|
90
90
|
headers: {},
|
91
91
|
connect_timeout: DEFAULT_CONNECT_TIMEOUT,
|
@@ -107,7 +107,7 @@ module SSE
|
|
107
107
|
if socket_factory
|
108
108
|
http_client_options["socket_class"] = socket_factory
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
if proxy
|
112
112
|
@proxy = proxy
|
113
113
|
else
|
@@ -202,12 +202,12 @@ module SSE
|
|
202
202
|
end
|
203
203
|
|
204
204
|
private
|
205
|
-
|
205
|
+
|
206
206
|
def reset_http
|
207
207
|
@http_client.close if !@http_client.nil?
|
208
208
|
close_connection
|
209
209
|
end
|
210
|
-
|
210
|
+
|
211
211
|
def close_connection
|
212
212
|
@lock.synchronize do
|
213
213
|
@cxn.connection.close if !@cxn.nil?
|
@@ -258,7 +258,7 @@ module SSE
|
|
258
258
|
interval = @first_attempt ? 0 : @backoff.next_interval
|
259
259
|
@first_attempt = false
|
260
260
|
if interval > 0
|
261
|
-
@logger.info { "Will retry connection after #{'%.3f' % interval} seconds" }
|
261
|
+
@logger.info { "Will retry connection after #{'%.3f' % interval} seconds" }
|
262
262
|
sleep(interval)
|
263
263
|
end
|
264
264
|
cxn = nil
|
@@ -268,14 +268,14 @@ module SSE
|
|
268
268
|
headers: build_headers
|
269
269
|
})
|
270
270
|
if cxn.status.code == 200
|
271
|
-
content_type = cxn.
|
271
|
+
content_type = cxn.content_type.mime_type
|
272
272
|
if content_type && content_type.start_with?("text/event-stream")
|
273
273
|
return cxn # we're good to proceed
|
274
274
|
else
|
275
275
|
reset_http
|
276
|
-
err = Errors::HTTPContentTypeError.new(
|
276
|
+
err = Errors::HTTPContentTypeError.new(content_type)
|
277
277
|
@on[:error].call(err)
|
278
|
-
@logger.warn { "Event source returned unexpected content type '#{
|
278
|
+
@logger.warn { "Event source returned unexpected content type '#{content_type}'" }
|
279
279
|
end
|
280
280
|
else
|
281
281
|
body = cxn.to_s # grab the whole response body in case it has error details
|
@@ -309,7 +309,7 @@ module SSE
|
|
309
309
|
# readpartial gives us a string, which may not be a valid UTF-8 string because a
|
310
310
|
# multi-byte character might not yet have been fully read, but BufferedLineReader
|
311
311
|
# will handle that.
|
312
|
-
rescue HTTP::TimeoutError
|
312
|
+
rescue HTTP::TimeoutError
|
313
313
|
# For historical reasons, we rethrow this as our own type
|
314
314
|
raise Errors::ReadTimeoutError.new(@read_timeout)
|
315
315
|
end
|
@@ -344,7 +344,7 @@ module SSE
|
|
344
344
|
@logger.warn { "#{message}: #{e.inspect}"}
|
345
345
|
@logger.debug { "Exception trace: #{e.backtrace}" }
|
346
346
|
begin
|
347
|
-
@on[:error].call(e)
|
347
|
+
@on[:error].call(e)
|
348
348
|
rescue StandardError => ee
|
349
349
|
@logger.warn { "Error handler threw an exception: #{ee.inspect}"}
|
350
350
|
@logger.debug { "Exception trace: #{ee.backtrace}" }
|
@@ -37,12 +37,15 @@ module SSE
|
|
37
37
|
event = maybe_create_event
|
38
38
|
reset_buffers
|
39
39
|
gen.yield event if !event.nil?
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
elsif (pos = line.index(':'))
|
41
|
+
name = line.slice(0...pos)
|
42
|
+
|
43
|
+
pos += 1 # skip colon
|
44
|
+
pos += 1 if pos < line.length && line[pos] == ' ' # skip optional single space, per SSE spec
|
45
|
+
line = line.slice(pos..-1)
|
46
|
+
|
47
|
+
item = process_field(name, line)
|
48
|
+
gen.yield item if !item.nil?
|
46
49
|
end
|
47
50
|
end
|
48
51
|
end
|
@@ -62,8 +65,11 @@ module SSE
|
|
62
65
|
when "event"
|
63
66
|
@type = value.to_sym
|
64
67
|
when "data"
|
65
|
-
|
66
|
-
|
68
|
+
if @have_data
|
69
|
+
@data << "\n" << value
|
70
|
+
else
|
71
|
+
@data = value
|
72
|
+
end
|
67
73
|
@have_data = true
|
68
74
|
when "id"
|
69
75
|
if !value.include?("\x00")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ld-eventsource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LaunchDarkly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
- !ruby/object:Gem::Version
|
137
137
|
version: '0'
|
138
138
|
requirements: []
|
139
|
-
rubygems_version: 3.
|
139
|
+
rubygems_version: 3.4.8
|
140
140
|
signing_key:
|
141
141
|
specification_version: 4
|
142
142
|
summary: LaunchDarkly SSE client
|