ld-celluloid-eventsource 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circle.yml +7 -0
- data/Contributing.md +7 -0
- data/README.md +2 -4
- data/ld-celluloid-eventsource.gemspec +1 -0
- data/lib/celluloid/eventsource/version.rb +1 -1
- data/lib/celluloid/eventsource.rb +36 -2
- data/spec/celluloid/eventsource_spec.rb +23 -0
- data/spec/spec_helper.rb +0 -2
- metadata +19 -4
- data/.travis.yml +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bd8fda8554cfa1dba5eb39bbf50070aa0d7106b
|
4
|
+
data.tar.gz: a16e16201da0c651b4528b4f213230e0200b743e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1d605c0cebbb138c600e8893760c7819237238c58cd20650c419cc9a79f98d3edea814698e25a627ad1767b2fe14e840696ae2de668dcaf10853a4709017dce
|
7
|
+
data.tar.gz: 8771be4c7e0dafce34b50018d4d9719460940c15eb86ea059c6bc140d96dbc2e0e1db079308868e09e48dd8869d80a50b5904f8bd16d5dc003a460354a93f993
|
data/.circle.yml
ADDED
data/Contributing.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Celluloid::Eventsource
|
2
|
+
|
3
|
+
To release:
|
4
|
+
1. Bump version in version.rb
|
5
|
+
1. Commit changes and tag with version: ie 0.8.4
|
6
|
+
1. `VERSION=0.8.4 && git tag $VERSION && git push origin $VERSION && gem build ld-celluloid-eventsource.gemspec && gem push ld-celluloid-eventsource-$VERSION.gem`
|
7
|
+
1. Release on Github
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Celluloid::Eventsource
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/celluloid-eventsource.png)](http://badge.fury.io/rb/celluloid-eventsource)
|
4
|
-
[![Code Climate](https://codeclimate.com/github/Tonkpils/celluloid-eventsource.png)](https://codeclimate.com/github/Tonkpils/celluloid-eventsource)
|
5
|
-
[![Build Status](https://travis-ci.org/Tonkpils/celluloid-eventsource.svg?branch=master)](https://travis-ci.org/Tonkpils/celluloid-eventsource)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/celluloid-eventsource.png)](http://badge.fury.io/rb/ld-celluloid-eventsource) [![CircleCI](https://circleci.com/gh/launchdarkly/celluloid-eventsource/tree/master.svg?style=svg)](https://circleci.com/gh/launchdarkly/celluloid-eventsource/tree/master)
|
6
4
|
|
7
5
|
An EventSource client based off Celluloid::IO.
|
8
6
|
|
@@ -12,7 +10,7 @@ Specification based on [EventSource](http://www.w3.org/TR/2012/CR-eventsource-20
|
|
12
10
|
|
13
11
|
Add this line to your application's Gemfile:
|
14
12
|
|
15
|
-
gem 'celluloid-eventsource'
|
13
|
+
gem 'ld-celluloid-eventsource'
|
16
14
|
|
17
15
|
And then execute:
|
18
16
|
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency 'celluloid-io', '~> 0.17.3'
|
22
22
|
spec.add_dependency 'celluloid', '~> 0.18.0.pre'
|
23
|
+
spec.add_dependency 'nio4r', '~> 1.1'
|
23
24
|
spec.add_dependency 'http_parser.rb', '~> 0.6.0'
|
24
25
|
|
25
26
|
spec.add_development_dependency 'atomic', '~> 1.1'
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'celluloid/current'
|
2
|
-
require
|
2
|
+
require 'celluloid/eventsource/version'
|
3
3
|
require 'celluloid/io'
|
4
4
|
require 'celluloid/eventsource/response_parser'
|
5
5
|
require 'uri'
|
6
|
+
require 'base64'
|
6
7
|
|
7
8
|
module Celluloid
|
8
9
|
class EventSource
|
@@ -24,6 +25,13 @@ module Celluloid
|
|
24
25
|
@ready_state = CONNECTING
|
25
26
|
@with_credentials = options.delete(:with_credentials) { false }
|
26
27
|
@headers = default_request_headers.merge(options.fetch(:headers, {}))
|
28
|
+
proxy = ENV['HTTP_PROXY'] || ENV['http_proxy'] || options[:proxy]
|
29
|
+
if proxy
|
30
|
+
proxyUri = URI(proxy)
|
31
|
+
if proxyUri.scheme == 'http' || proxyUri.scheme == 'https'
|
32
|
+
@proxy = proxyUri
|
33
|
+
end
|
34
|
+
end
|
27
35
|
|
28
36
|
@event_type_buffer = ""
|
29
37
|
@last_event_id_buffer = ""
|
@@ -96,7 +104,22 @@ module Celluloid
|
|
96
104
|
end
|
97
105
|
|
98
106
|
def establish_connection
|
99
|
-
|
107
|
+
if @proxy
|
108
|
+
sock = ::TCPSocket.new(@proxy.host, @proxy.port)
|
109
|
+
@socket = Celluloid::IO::TCPSocket.new(sock)
|
110
|
+
|
111
|
+
@socket.write(connect_string)
|
112
|
+
@socket.flush
|
113
|
+
while (line = @socket.readline.chomp) != '' do @parser << line end
|
114
|
+
|
115
|
+
unless @parser.status_code == 200
|
116
|
+
@on[:error].call({status_code: @parser.status_code, body: @parser.chunk})
|
117
|
+
return
|
118
|
+
end
|
119
|
+
else
|
120
|
+
sock = ::TCPSocket.new(@url.host, @url.port)
|
121
|
+
@socket = Celluloid::IO::TCPSocket.new(sock)
|
122
|
+
end
|
100
123
|
|
101
124
|
if ssl?
|
102
125
|
@socket = Celluloid::IO::SSLSocket.new(@socket)
|
@@ -104,6 +127,7 @@ module Celluloid
|
|
104
127
|
end
|
105
128
|
|
106
129
|
@socket.write(request_string)
|
130
|
+
@socket.flush()
|
107
131
|
|
108
132
|
until @parser.headers?
|
109
133
|
@parser << @socket.readline
|
@@ -234,6 +258,16 @@ module Celluloid
|
|
234
258
|
["GET #{url.request_uri} HTTP/1.1", headers].flatten.join("\r\n").concat("\r\n\r\n")
|
235
259
|
end
|
236
260
|
|
261
|
+
def connect_string
|
262
|
+
req = "CONNECT #{url.host}:#{url.port} HTTP/1.1\r\n"
|
263
|
+
req << "Host: #{url.host}:#{url.port}\r\n"
|
264
|
+
if @proxy.user || @proxy.password
|
265
|
+
encoded_credentials = Base64.strict_encode64([@proxy.user || '', @proxy.password || ''].join(":"))
|
266
|
+
req << "Proxy-Authorization: Basic #{encoded_credentials}\r\n"
|
267
|
+
end
|
268
|
+
req << "\r\n"
|
269
|
+
end
|
270
|
+
|
237
271
|
end
|
238
272
|
|
239
273
|
end
|
@@ -39,6 +39,28 @@ RSpec.describe Celluloid::EventSource do
|
|
39
39
|
headers = es.instance_variable_get('@headers')
|
40
40
|
expect(headers['Authorization']).to eq(auth_header["Authorization"])
|
41
41
|
end
|
42
|
+
|
43
|
+
it 'parses an http proxy' do
|
44
|
+
proxy = "http://myhost:8080"
|
45
|
+
allow_any_instance_of(Celluloid::EventSource).to receive_message_chain(:async, :listen)
|
46
|
+
es = Celluloid::EventSource.new("http://#{url}", :proxy => proxy)
|
47
|
+
|
48
|
+
instanceProxy = es.instance_variable_get('@proxy')
|
49
|
+
expect(instanceProxy.host).to eq('myhost')
|
50
|
+
expect(instanceProxy.port).to eq(8080)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'parses an http proxy auth' do
|
54
|
+
proxy = "http://user:pass@myhost:8080"
|
55
|
+
allow_any_instance_of(Celluloid::EventSource).to receive_message_chain(:async, :listen)
|
56
|
+
es = Celluloid::EventSource.new("http://#{url}", :proxy => proxy)
|
57
|
+
|
58
|
+
instanceProxy = es.instance_variable_get('@proxy')
|
59
|
+
expect(instanceProxy.host).to eq('myhost')
|
60
|
+
expect(instanceProxy.port).to eq(8080)
|
61
|
+
expect(instanceProxy.user).to eq('user')
|
62
|
+
expect(instanceProxy.password).to eq('pass')
|
63
|
+
end
|
42
64
|
end
|
43
65
|
|
44
66
|
context 'callbacks' do
|
@@ -67,6 +89,7 @@ RSpec.describe Celluloid::EventSource do
|
|
67
89
|
|
68
90
|
Celluloid::EventSource.new("#{dummy.endpoint}/error") do |conn|
|
69
91
|
conn.on_error do |error|
|
92
|
+
conn.close
|
70
93
|
future.signal(value_class.new({ msg: error, state: conn.ready_state }))
|
71
94
|
end
|
72
95
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ld-celluloid-eventsource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LaunchDarkly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid-io
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.18.0.pre
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nio4r
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.1'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: http_parser.rb
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,9 +144,10 @@ executables: []
|
|
130
144
|
extensions: []
|
131
145
|
extra_rdoc_files: []
|
132
146
|
files:
|
147
|
+
- ".circle.yml"
|
133
148
|
- ".gitignore"
|
134
149
|
- ".rspec"
|
135
|
-
-
|
150
|
+
- Contributing.md
|
136
151
|
- Gemfile
|
137
152
|
- LICENSE
|
138
153
|
- README.md
|
@@ -167,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
182
|
version: '0'
|
168
183
|
requirements: []
|
169
184
|
rubyforge_project:
|
170
|
-
rubygems_version: 2.6.
|
185
|
+
rubygems_version: 2.6.11
|
171
186
|
signing_key:
|
172
187
|
specification_version: 4
|
173
188
|
summary: ld-celluloid-eventsource is a gem to consume SSE streaming API.
|