Skip to content

Commit 6ff79d2

Browse files
committed
fix(transport/http): never stop processing queue in HTTP drivers
1 parent 67c62c9 commit 6ff79d2

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

shard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: placeos-driver
2-
version: 7.11.4
2+
version: 7.11.5
33

44
dependencies:
55
action-controller:

spec/transport_http_spec.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ describe PlaceOS::Driver::TransportHTTP do
44
it "should perform a secure request" do
55
responses = 0
66
queue = Helper.queue
7-
transport = PlaceOS::Driver::TransportHTTP.new(queue, "https://www.google.com.au/", ::PlaceOS::Driver::Settings.new(%({"disable_cookies": true}))) do
7+
transport = PlaceOS::Driver::TransportHTTP.new(queue, "https://www.google.com/", ::PlaceOS::Driver::Settings.new(%({"disable_cookies": true}))) do
88
responses += 1
99
end
1010
transport.before_request do |request|
11-
request.hostname.should eq "www.google.com.au"
11+
request.hostname.should eq "www.google.com"
1212
end
1313
transport.connect
1414
queue.online.should eq(true)

src/placeos-driver/transport/http.cr

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class PlaceOS::Driver
144144
@max_requests : Int32
145145
@ip : String
146146
@tls : OpenSSL::SSL::Context::Client?
147+
@connected_state : Bool = true
147148

148149
property :received
149150

@@ -157,6 +158,18 @@ class PlaceOS::Driver
157158
@queue.online = true
158159
end
159160

161+
# don't stop processing commands in HTTP drivers
162+
# the requests are required to re-enable the queue
163+
# and queue based HTTP drivers are less common
164+
protected def set_connected_state(state : Bool)
165+
@connected_state = state
166+
if state && !@queue.online
167+
@queue.online = true
168+
else
169+
@queue.set_connected state
170+
end
171+
end
172+
160173
protected def __is_https?
161174
(@uri_base.scheme || "http").ends_with?('s')
162175
end
@@ -257,14 +270,14 @@ class PlaceOS::Driver
257270
end
258271
end
259272

260-
# assuming we're typically online, this check before assignment is more performant
261-
@queue.online = true unless @queue.online
273+
# we don't want to be calling connected callback each time a request succeeds
274+
set_connected_state(true) unless @connected_state
262275
@received.call
263276

264277
# fallback in case the HTTP client lib doesn't decompress the response
265278
check_http_response_encoding response
266279
rescue error : IO::Error | ArgumentError
267-
@queue.online = false
280+
set_connected_state(false)
268281
raise error
269282
end
270283

0 commit comments

Comments
 (0)