Skip to content

Commit f793e9f

Browse files
committed
fix(http_client): class level execute should default to proxy use
without forcing it on manually initialized classes
1 parent 04e39bc commit f793e9f

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

shard.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: connect-proxy
2-
version: 2.0.1
2+
version: 2.0.2
33
license: MIT
44
crystal: ">= 0.36.1"
55

src/connect-proxy/http_client.cr

+10-23
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,17 @@ module ConnectProxy::ProxyHTTP
2020
yield new(uri, tls, ignore_env)
2121
end
2222

23-
# for some reason previous_def doesn't work for these when extending HTTP::Client
24-
{% begin %}
25-
{% if @type.stringify != "HTTP::Client" %}
26-
def self.new(io : IO, host : String = "", port : Int32 = 80)
27-
inst = super(io, host, port)
28-
29-
if ConnectProxy.behind_proxy?
30-
inst.set_proxy ConnectProxy.new(*ConnectProxy.parse_proxy_url)
31-
end
32-
33-
inst
34-
end
35-
36-
def self.new(host : String, port : Int32? = nil, tls : TLSContext = nil)
37-
inst = super(host, port, tls)
38-
39-
if ConnectProxy.behind_proxy?
40-
inst.set_proxy ConnectProxy.new(*ConnectProxy.parse_proxy_url)
41-
end
42-
43-
inst
23+
def self.new(host : String, port = nil, tls : TLSContext = nil, &)
24+
client = new(host, port, tls)
25+
begin
26+
if ConnectProxy.behind_proxy?
27+
client.set_proxy ConnectProxy.new(*ConnectProxy.parse_proxy_url)
4428
end
45-
{% end %}
46-
{% end %}
29+
yield client
30+
ensure
31+
client.close
32+
end
33+
end
4734
end
4835

4936
def set_proxy(proxy : ConnectProxy = nil)

0 commit comments

Comments
 (0)