Skip to content

Commit 082ba42

Browse files
committed
fix(transport/http): remove @tls instance variable
1 parent 13ae356 commit 082ba42

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

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.7.0
2+
version: 7.7.1
33

44
dependencies:
55
action-controller:

src/placeos-driver/interface/sensor.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ abstract class PlaceOS::Driver
178178
def convert_measurement_to(other_unit : String)
179179
this_unit = self.unit
180180
return self.value unless this_unit
181-
181+
182182
Units::Measurement.new(self.value, this_unit).convert_to(other_unit).to_f
183183
end
184184
end

src/placeos-driver/transport/http.cr

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ class PlaceOS::Driver
120120
&@received : -> Nil
121121
)
122122
@terminated = false
123-
@tls = new_tls_context
124123
@uri_base = URI.parse(@uri)
125124
@ip = @uri_base.hostname.not_nil!
126125
@http_client_mutex = Mutex.new
@@ -134,12 +133,11 @@ class PlaceOS::Driver
134133
@client_idle = Time.monotonic
135134
@client_requests = 0
136135

137-
context = __is_https? ? @tls : nil
136+
context = __is_https? ? new_tls_context : nil
138137
@client = new_http_client(@uri_base, context)
139138
end
140139

141140
@params_base : URI::Params
142-
@tls : OpenSSL::SSL::Context::Client
143141
@client : ConnectProxy::HTTPClient
144142
@client_idle : Time::Span
145143
@keep_alive : Time::Span
@@ -158,22 +156,22 @@ class PlaceOS::Driver
158156
@queue.online = true
159157
end
160158

161-
def start_tls(verify_mode = OpenSSL::SSL::VerifyMode::NONE, context = @tls) : Nil
162-
tls = context || OpenSSL::SSL::Context::Client.new
163-
tls.verify_mode = verify_mode
164-
@tls = tls
159+
def start_tls(verify_mode : OpenSSL::SSL::VerifyMode, context : OpenSSL::SSL::Context = new_tls_context) : Nil
160+
context.verify_mode = verify_mode
165161

166162
# Re-create the client with the new TLS configuration
167-
@client = new_http_client(@uri_base, @tls)
163+
@http_client_mutex.synchronize do
164+
@client = new_http_client(@uri_base, context)
165+
@client_requests = 0
166+
end
168167
end
169168

170169
protected def __is_https?
171170
(@uri_base.scheme || "http").ends_with?('s')
172171
end
173172

174173
protected def __new_http_client
175-
@tls = new_tls_context
176-
context = __is_https? ? @tls : nil
174+
context = __is_https? ? new_tls_context : nil
177175

178176
begin
179177
@client.try &.close
@@ -262,7 +260,10 @@ class PlaceOS::Driver
262260
# Does this request require a TLS context?
263261
context = __is_https? ? new_tls_context : nil
264262
client = new_http_client(uri, context)
265-
client.exec(method.to_s.upcase, uri.request_target, headers, body).tap { client.close }
263+
client.exec(method.to_s.upcase, uri.request_target, headers, body).tap do
264+
client.close
265+
context = nil
266+
end
266267
else
267268
# Only a single request can occur at a time
268269
# crystal does not provide any queuing mechanism so this mutex does the trick

0 commit comments

Comments
 (0)