Skip to content

Commit

Permalink
Merge pull request #29 from mamantoha/proxy-client-write-timeout
Browse files Browse the repository at this point in the history
proxy client write timeout
  • Loading branch information
mamantoha authored Feb 13, 2023
2 parents fe82cf6 + afa51fc commit 012ea2b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

* Add `HTTP::Proxy::Client#write_timeout` ([#29](https://github.com/mamantoha/http_proxy/pull/29))
* Add specs for proxy client with auth ([#28](https://github.com/mamantoha/http_proxy/pull/28))

## 0.10.0

* Refactor `HTTP::Proxy::Client`
Expand Down
3 changes: 2 additions & 1 deletion src/ext/http/client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ module HTTP
tls: @tls,
dns_timeout: @dns_timeout,
connect_timeout: @connect_timeout,
read_timeout: @read_timeout
read_timeout: @read_timeout,
write_timeout: @write_timeout
)
rescue ex : IO::Error
raise IO::Error.new("Failed to open TCP connection to #{@host}:#{@port} (#{ex.message})")
Expand Down
7 changes: 5 additions & 2 deletions src/http/proxy/client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module HTTP
@dns_timeout : Float64?
@connect_timeout : Float64?
@read_timeout : Float64?
@write_timeout : Float64?

# Creates a new socket factory that tunnels via the given host and port.
# The following optional arguments are supported:
Expand All @@ -42,10 +43,11 @@ module HTTP

# Returns a new socket connected to the given host and port via the
# proxy that was requested when the socket factory was instantiated.
def open(host, port, tls = nil, *, @dns_timeout, @connect_timeout, @read_timeout) : IO
def open(host, port, tls = nil, *, @dns_timeout, @connect_timeout, @read_timeout, @write_timeout) : IO
socket = TCPSocket.new(@host, @port, @dns_timeout, @connect_timeout)
socket.read_timeout = @read_timeout if @read_timeout
socket.sync = true
socket.write_timeout = @write_timeout if @write_timeout
socket.sync = false

if tls
socket << "CONNECT #{host}:#{port} HTTP/1.1\r\n"
Expand All @@ -65,6 +67,7 @@ module HTTP
end

socket << "\r\n"
socket.flush

resp = HTTP::Client::Response.from_io(socket, ignore_body: true)

Expand Down

0 comments on commit 012ea2b

Please sign in to comment.