Skip to content

Commit

Permalink
Include Host header for CONNECT proxy requests (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
soedar authored May 22, 2021
1 parent c63f12e commit d4a7bbe
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Include `Host` header for `CONNECT` proxy requests ([#714])

## [0.9.8] - 2020-05-02
### Fixed
Expand Down
5 changes: 4 additions & 1 deletion src/ConnectionRequest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ sockettype(url::URI, default) = url.scheme in ("wss", "https") ? SSLContext : de
function connect_tunnel(io, target_url, req)
target = "$(URIs.hoststring(target_url.host)):$(target_url.port)"
@debug 1 "📡 CONNECT HTTPS tunnel to $target"
headers = Dict(filter(x->x.first == "Proxy-Authorization", req.headers))
headers = Dict("Host" => target)
if (auth = header(req, "Proxy-Authorization"); !isempty(auth))
headers["Proxy-Authorization"] = auth
end
request = Request("CONNECT", target, headers)
writeheaders(io, request)
startread(io)
Expand Down
30 changes: 30 additions & 0 deletions test/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,33 @@ end
test(HTTP.delete(uri, headers, body; query=query), "DELETE")
end
end

@testset "HTTP CONNECT Proxy" begin
@testset "Host header" begin
# Stores the http request passed by the client
req = String[]

# Trivial implementation of a proxy server
# We are only interested in the request passed in by the client
# Returns 400 after reading the http request into req
proxy = listen(IPv4(0), 8082)
@async begin
sock = accept(proxy)
while isopen(sock)
line = readline(sock)
isempty(line) && break

push!(req, line)
end
write(sock, "HTTP/1.1 400 Bad Request\r\n\r\n")
end

# Make the HTTP request
HTTP.get("https://example.com"; proxy="http://localhost:8082", retry=false, status_exception=false)

# Test if the host header exist in the request
@test "Host: example.com:443" in req

close(proxy)
end
end

0 comments on commit d4a7bbe

Please sign in to comment.