em-eventsource 0.2.0 → 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.
Files changed (5) hide show
  1. checksums.yaml +6 -14
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +10 -5
  4. data/lib/em-eventsource.rb +29 -9
  5. metadata +27 -27
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZjlhZjYyOTUyZDQwZTE5MjcyYjE0Y2FmOTczMWI3ODk3ZGRhZGNiMA==
5
- data.tar.gz: !binary |-
6
- NjhlNjk1ZjgwNTE0YjlkZDUwODM0ZjE4ZGNjYmFlMjA5OTM1NzY2OA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- N2E0NWU5YWNmMWNjYTUzNDA1YjFiOWI1ZTllYzdkOWQ3YjAwOWNkNTk3Yzg0
10
- Yjg1MzdhMTBiZjIxYTVjZjBkMGJmZDA0NTI0MTc5NWE0ZmRhNDE2Yjc4MjQ4
11
- OGY4YmZiZDdjM2E4M2I3NGJiNTJhZjQ3YWQxYzVhMGEzMmVkYmU=
12
- data.tar.gz: !binary |-
13
- OThjZDhhM2Q3ZGE1ODAzNWU5ZGIwZjUyY2ZhNTNkNDM2ZDg5NzFlNGJjYTc4
14
- NzA1Y2QzN2IxMjcxNWMzZTJhNmM4MDdjNDQyYmVmYjg1YTE1YWY4NTQ5OTI0
15
- NTI3MmMzMGM5YjEyMjAzMDI3NmJhNDAwNDkzM2E0YTEwODZkZDU=
2
+ SHA256:
3
+ metadata.gz: f824fba4e073244ab8f97abd68a1e638edee0f5c13f317040f9dc15b64ffe242
4
+ data.tar.gz: 9a560157f4bd6d8445e51b1eec508d63731e5d1c9f5b1be2505bae63ee50ba30
5
+ SHA512:
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
@@ -1,6 +1,6 @@
1
1
  # EventSource client for EventMachine
2
2
 
3
- See the specification: http://dev.w3.org/html5/eventsource/
3
+ See the specification: https://html.spec.whatwg.org/multipage/server-sent-events.html
4
4
 
5
5
  ## Install
6
6
 
@@ -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.1.2"
13
+ gem "em-eventsource", "~> 0.3.0"
14
14
 
15
15
  ## Usage
16
16
 
@@ -60,7 +60,11 @@ source.close
60
60
  Current status of the connection:
61
61
 
62
62
  ```ruby
63
- source.ready_state # Can be EM::EventSource::CLOSED, EM::EventSource::CONNECTING, EM::EventSource::OPEN
63
+ # Can be:
64
+ # - EM::EventSource::CLOSED
65
+ # - EM::EventSource::CONNECTING
66
+ # - EM::EventSource::OPEN
67
+ source.ready_state
64
68
  ```
65
69
 
66
70
  Override the default retry value (if the connection is lost):
@@ -91,8 +95,9 @@ source.inactivity_timeout = 120 # in seconds (default: 60).
91
95
 
92
96
  MIT License
93
97
 
94
- Copyright (C) 2012 by François de Metz
95
- Copyright (C) 2011 by af83
98
+ Copyright (C) 2018 François de Metz
99
+
100
+ Copyright (C) 2011 af83
96
101
 
97
102
  Permission is hereby granted, free of charge, to any person obtaining a copy
98
103
  of this software and associated documentation files (the "Software"), to deal
@@ -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
@@ -88,7 +89,8 @@ module EventMachine
88
89
  #
89
90
  # Returns nothing
90
91
  def use(*args, &block)
91
- @middlewares << (args << block)
92
+ block = args.pop if block.nil? && block_given?
93
+ @middlewares << [args, block]
92
94
  end
93
95
 
94
96
  # Start subscription
@@ -116,6 +118,9 @@ module EventMachine
116
118
  @req.callback(&method(:handle_reconnect))
117
119
  buffer = ""
118
120
  @req.stream do |chunk|
121
+ unless chunk.valid_encoding?
122
+ chunk.scrub!('?')
123
+ end
119
124
  buffer += chunk
120
125
  while index = buffer.index(/\r\n\r\n|\n\n/)
121
126
  stream = buffer.slice!(0..index)
@@ -126,6 +131,13 @@ module EventMachine
126
131
 
127
132
  def handle_reconnect(*args)
128
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
+
129
141
  @ready_state = CONNECTING
130
142
  @errors.each { |error| error.call("Connection lost. Reconnecting.") }
131
143
  EM.add_timer(@retry) do
@@ -134,6 +146,10 @@ module EventMachine
134
146
  end
135
147
 
136
148
  def handle_headers(headers)
149
+ if headers.redirection?
150
+ @req.close
151
+ return
152
+ end
137
153
  if headers.status != 200
138
154
  close
139
155
  @errors.each { |error| error.call("Unexpected response status #{headers.status}") }
@@ -164,7 +180,7 @@ module EventMachine
164
180
  end
165
181
  /^retry:(.+)$/.match(part) do |m|
166
182
  if m[1].strip! =~ /^[0-9]+$/
167
- @retry = m[1].to_i
183
+ @retry = m[1].to_i / 1000
168
184
  end
169
185
  end
170
186
  end
@@ -178,15 +194,19 @@ module EventMachine
178
194
  end
179
195
 
180
196
  def prepare_request
181
- conn = EM::HttpRequest.new(@url, :inactivity_timeout => @inactivity_timeout)
182
- @middlewares.each { |middleware|
183
- block = middleware.pop
184
- conn.use(*middleware, &block)
185
- }
197
+ conn = EM::HttpRequest.new(@url, {tls: {verify_peer: true}, inactivity_timeout: @inactivity_timeout})
198
+ @middlewares.each do |middleware, block|
199
+ if block
200
+ conn.use(*middleware, &block)
201
+ else
202
+ conn.use(*middleware)
203
+ end
204
+ end
186
205
  headers = @headers.merge({'Cache-Control' => 'no-cache', 'Accept' => 'text/event-stream'})
187
206
  headers.merge!({'Last-Event-Id' => @last_event_id }) if not @last_event_id.nil?
188
- [conn, conn.get({ :query => @query,
189
- :head => headers})]
207
+ [conn, conn.get({ query: @query,
208
+ head: headers,
209
+ keepalive: true })]
190
210
  end
191
211
  end
192
212
  end
metadata CHANGED
@@ -1,111 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-eventsource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
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: 2014-08-11 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
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0.beta3
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.0.beta3
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: em-http-request
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.0
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.0.0
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '2.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest-spec-context
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description: ! " em-eventsource is an eventmachine library to consume Server-Sent
98
- Events streaming API.\n You can find the specification here: http://dev.w3.org/html5/eventsource/\n"
97
+ description: |2
98
+ em-eventsource is an eventmachine library to consume Server-Sent Events streaming API.
99
+ You can find the specification here: http://dev.w3.org/html5/eventsource/
99
100
  email: francois@2metz.fr
100
101
  executables: []
101
102
  extensions: []
102
103
  extra_rdoc_files:
103
104
  - README.md
104
105
  files:
105
- - README.md
106
+ - CHANGELOG.md
106
107
  - Gemfile
108
+ - README.md
107
109
  - lib/em-eventsource.rb
108
- homepage: http://github.com/AF83/em-eventsource
110
+ homepage: https://github.com/francois2metz/em-eventsource
109
111
  licenses: []
110
112
  metadata: {}
111
113
  post_install_message:
@@ -114,20 +116,18 @@ require_paths:
114
116
  - lib
115
117
  required_ruby_version: !ruby/object:Gem::Requirement
116
118
  requirements:
117
- - - ! '>='
119
+ - - ">="
118
120
  - !ruby/object:Gem::Version
119
121
  version: '0'
120
122
  required_rubygems_version: !ruby/object:Gem::Requirement
121
123
  requirements:
122
- - - ! '>='
124
+ - - ">="
123
125
  - !ruby/object:Gem::Version
124
126
  version: '0'
125
127
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.0.7
128
+ rubygems_version: 3.0.3
128
129
  signing_key:
129
130
  specification_version: 4
130
131
  summary: em-eventsource is an eventmachine library to consume Server-Sent Events streaming
131
132
  API.
132
133
  test_files: []
133
- has_rdoc: