diff --git a/src/http_client.jl b/src/http_client.jl index d2b9015ae..a450ce54d 100644 --- a/src/http_client.jl +++ b/src/http_client.jl @@ -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 diff --git a/test/http_client_tests.jl b/test/http_client_tests.jl index 6d8d2f8b7..ff8bb3ab6 100644 --- a/test/http_client_tests.jl +++ b/test/http_client_tests.jl @@ -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)) @@ -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 @@ -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)