ld-eventsource 2.1.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/ld-eventsource/client.rb +39 -46
- data/lib/ld-eventsource/events.rb +5 -1
- data/lib/ld-eventsource/impl/backoff.rb +5 -1
- data/lib/ld-eventsource/impl/buffered_line_reader.rb +82 -0
- data/lib/ld-eventsource/impl/event_parser.rb +26 -14
- data/lib/ld-eventsource/version.rb +1 -1
- metadata +5 -29
- data/.circleci/config.yml +0 -39
- data/.gitignore +0 -17
- data/.ldrelease/circleci/linux/execute.sh +0 -18
- data/.ldrelease/circleci/mac/execute.sh +0 -18
- data/.ldrelease/circleci/template/build.sh +0 -19
- data/.ldrelease/circleci/template/gems-setup.sh +0 -16
- data/.ldrelease/circleci/template/prepare.sh +0 -17
- data/.ldrelease/circleci/template/publish.sh +0 -19
- data/.ldrelease/circleci/template/test.sh +0 -10
- data/.ldrelease/circleci/template/update-version.sh +0 -8
- data/.ldrelease/circleci/windows/execute.ps1 +0 -19
- data/.ldrelease/config.yml +0 -22
- data/CHANGELOG.md +0 -35
- data/Gemfile +0 -3
- data/ld-eventsource.gemspec +0 -30
- data/scripts/gendocs.sh +0 -12
- data/scripts/release.sh +0 -30
- data/spec/backoff_spec.rb +0 -52
- data/spec/client_spec.rb +0 -444
- data/spec/event_parser_spec.rb +0 -100
- data/spec/http_stub.rb +0 -83
data/spec/event_parser_spec.rb
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
require "ld-eventsource/impl/event_parser"
|
2
|
-
|
3
|
-
describe SSE::Impl::EventParser do
|
4
|
-
subject { SSE::Impl::EventParser }
|
5
|
-
|
6
|
-
it "parses an event with all fields" do
|
7
|
-
lines = [
|
8
|
-
"event: abc\r\n",
|
9
|
-
"data: def\r\n",
|
10
|
-
"id: 1\r\n",
|
11
|
-
"\r\n"
|
12
|
-
]
|
13
|
-
ep = subject.new(lines)
|
14
|
-
|
15
|
-
expected_event = SSE::StreamEvent.new(:abc, "def", "1")
|
16
|
-
output = ep.items.to_a
|
17
|
-
expect(output).to eq([ expected_event ])
|
18
|
-
end
|
19
|
-
|
20
|
-
it "parses an event with only data" do
|
21
|
-
lines = [
|
22
|
-
"data: def\r\n",
|
23
|
-
"\r\n"
|
24
|
-
]
|
25
|
-
ep = subject.new(lines)
|
26
|
-
|
27
|
-
expected_event = SSE::StreamEvent.new(:message, "def", nil)
|
28
|
-
output = ep.items.to_a
|
29
|
-
expect(output).to eq([ expected_event ])
|
30
|
-
end
|
31
|
-
|
32
|
-
it "parses an event with multi-line data" do
|
33
|
-
lines = [
|
34
|
-
"data: def\r\n",
|
35
|
-
"data: ghi\r\n",
|
36
|
-
"\r\n"
|
37
|
-
]
|
38
|
-
ep = subject.new(lines)
|
39
|
-
|
40
|
-
expected_event = SSE::StreamEvent.new(:message, "def\nghi", nil)
|
41
|
-
output = ep.items.to_a
|
42
|
-
expect(output).to eq([ expected_event ])
|
43
|
-
end
|
44
|
-
|
45
|
-
it "ignores comments" do
|
46
|
-
lines = [
|
47
|
-
":",
|
48
|
-
"data: def\r\n",
|
49
|
-
":",
|
50
|
-
"\r\n"
|
51
|
-
]
|
52
|
-
ep = subject.new(lines)
|
53
|
-
|
54
|
-
expected_event = SSE::StreamEvent.new(:message, "def", nil)
|
55
|
-
output = ep.items.to_a
|
56
|
-
expect(output).to eq([ expected_event ])
|
57
|
-
end
|
58
|
-
|
59
|
-
it "parses reconnect interval" do
|
60
|
-
lines = [
|
61
|
-
"retry: 2500\r\n",
|
62
|
-
"\r\n"
|
63
|
-
]
|
64
|
-
ep = subject.new(lines)
|
65
|
-
|
66
|
-
expected_item = SSE::Impl::SetRetryInterval.new(2500)
|
67
|
-
output = ep.items.to_a
|
68
|
-
expect(output).to eq([ expected_item ])
|
69
|
-
end
|
70
|
-
|
71
|
-
it "parses multiple events" do
|
72
|
-
lines = [
|
73
|
-
"event: abc\r\n",
|
74
|
-
"data: def\r\n",
|
75
|
-
"id: 1\r\n",
|
76
|
-
"\r\n",
|
77
|
-
"data: ghi\r\n",
|
78
|
-
"\r\n"
|
79
|
-
]
|
80
|
-
ep = subject.new(lines)
|
81
|
-
|
82
|
-
expected_event_1 = SSE::StreamEvent.new(:abc, "def", "1")
|
83
|
-
expected_event_2 = SSE::StreamEvent.new(:message, "ghi", nil)
|
84
|
-
output = ep.items.to_a
|
85
|
-
expect(output).to eq([ expected_event_1, expected_event_2 ])
|
86
|
-
end
|
87
|
-
|
88
|
-
it "ignores events with no data" do
|
89
|
-
lines = [
|
90
|
-
"event: nothing\r\n",
|
91
|
-
"\r\n",
|
92
|
-
"event: nada\r\n",
|
93
|
-
"\r\n"
|
94
|
-
]
|
95
|
-
ep = subject.new(lines)
|
96
|
-
|
97
|
-
output = ep.items.to_a
|
98
|
-
expect(output).to eq([])
|
99
|
-
end
|
100
|
-
end
|
data/spec/http_stub.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
require "webrick"
|
2
|
-
require "webrick/httpproxy"
|
3
|
-
require "webrick/https"
|
4
|
-
|
5
|
-
class StubHTTPServer
|
6
|
-
attr_reader :port
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@port = 50000
|
10
|
-
begin
|
11
|
-
@server = create_server(@port)
|
12
|
-
rescue Errno::EADDRINUSE
|
13
|
-
@port += 1
|
14
|
-
retry
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def create_server(port)
|
19
|
-
WEBrick::HTTPServer.new(
|
20
|
-
BindAddress: '127.0.0.1',
|
21
|
-
Port: port,
|
22
|
-
AccessLog: [],
|
23
|
-
Logger: NullLogger.new
|
24
|
-
)
|
25
|
-
end
|
26
|
-
|
27
|
-
def start
|
28
|
-
Thread.new { @server.start }
|
29
|
-
end
|
30
|
-
|
31
|
-
def stop
|
32
|
-
@server.shutdown
|
33
|
-
end
|
34
|
-
|
35
|
-
def base_uri
|
36
|
-
URI("http://127.0.0.1:#{@port}")
|
37
|
-
end
|
38
|
-
|
39
|
-
def setup_response(uri_path, &action)
|
40
|
-
@server.mount_proc(uri_path, action)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class StubProxyServer < StubHTTPServer
|
45
|
-
attr_reader :request_count
|
46
|
-
attr_accessor :connect_status
|
47
|
-
|
48
|
-
def initialize
|
49
|
-
super
|
50
|
-
@request_count = 0
|
51
|
-
end
|
52
|
-
|
53
|
-
def create_server(port)
|
54
|
-
WEBrick::HTTPProxyServer.new(
|
55
|
-
BindAddress: '127.0.0.1',
|
56
|
-
Port: port,
|
57
|
-
AccessLog: [],
|
58
|
-
Logger: NullLogger.new,
|
59
|
-
ProxyContentHandler: proc do |req,res|
|
60
|
-
if !@connect_status.nil?
|
61
|
-
res.status = @connect_status
|
62
|
-
end
|
63
|
-
@request_count += 1
|
64
|
-
end
|
65
|
-
)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
class NullLogger
|
70
|
-
def method_missing(*)
|
71
|
-
self
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def with_server(server = nil)
|
76
|
-
server = StubHTTPServer.new if server.nil?
|
77
|
-
begin
|
78
|
-
server.start
|
79
|
-
yield server
|
80
|
-
ensure
|
81
|
-
server.stop
|
82
|
-
end
|
83
|
-
end
|