Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/http_client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ end

function _apply_default_accept_encoding!(headers::Headers, decompress::Union{Nothing,Bool})::Nothing
decompress === false && return nothing
hasheader(headers, "Accept-Encoding") && return nothing
any(h -> h[1] == "Accept-Encoding", headers.entries) && return nothing
setheader(headers, "Accept-Encoding", "gzip, deflate")
return nothing
end
Expand Down
10 changes: 9 additions & 1 deletion test/http_client_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ end
base_url = "http://$(address)"
accept_encodings = Dict{String, Union{Nothing, String}}()
server_task = errormonitor(Threads.@spawn begin
for _ in 1:13
for _ in 1:14
conn = NC.accept(listener)
try
req = HT.read_request(HT._ConnReader(conn))
Expand Down Expand Up @@ -1691,6 +1691,9 @@ end
headers = HT.Headers()
HT.setheader(headers, "Content-Encoding", "deflate")
_send_response_bytes_client!(conn, req; body_bytes = payload, headers = headers, close_conn = true)
elseif req.target == "/accept-encoding-empty"
accept_encodings[req.target] = HT.header(req.headers, "Accept-Encoding", nothing)
_send_response_client!(conn, req; body_text = "ok", close_conn = true)
else
_send_response_client!(conn, req; status = 500, reason = "Unexpected", body_text = req.target, close_conn = true)
end
Expand Down Expand Up @@ -1789,6 +1792,11 @@ end
@test String(resp_deflate_buffer.body) == "deflate-buffer"
@test accept_encodings["/deflate-buffer"] == "gzip, deflate"

# RFC 9110 §12.5.3: an explicit Accept-Encoding: "" must not be overwritten
resp_ae_empty = HT.get("$(base_url)/accept-encoding-empty"; headers = ["Accept-Encoding" => ""])
@test resp_ae_empty.status == 200
@test accept_encodings["/accept-encoding-empty"] == ""

_wait_task_client!(server_task)
finally
HTTP.@try_ignore NC.close(listener)
Expand Down
Loading