authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2023-03-23 10:05:58+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-03-23 10:05:58+01:00
log9fedecf4ab6035dca596648cd31ce85798ad69d5
treef09a7b1be9c2eabfbebaf879f26a1a6da640276a
parentdc6b05408a4bf0a9a52eb0532b7dddc06914ad5d
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

http.Client: don't prematurely check transfer_{encoding,compression} (#15040)

Common headers in a response are: Content-Encoding: gzip Transfer-Encoding: chunked We used to return `HttpHeadersInvalid` if a `Transfer-Encoding` header was received while the compression was already set. However, Transfer-Encoding may not include compression. We should only return an error if we are setting a value that was already set. Fixes compatibility with a bunch of websites.

1 files changed, 2 insertions(+), 2 deletions(-)

lib/std/http/Client/Response.zig+2-2
......@@ -74,8 +74,6 @@ pub const Headers = struct {
7474 if (headers.content_length != null) return error.HttpHeadersInvalid;
7575 headers.content_length = try std.fmt.parseInt(u64, header_value, 10);
7676 } else if (std.ascii.eqlIgnoreCase(header_name, "transfer-encoding")) {
77 if (headers.transfer_encoding != null or headers.transfer_compression != null) return error.HttpHeadersInvalid;
78
7977 // Transfer-Encoding: second, first
8078 // Transfer-Encoding: deflate, chunked
8179 var iter = std.mem.splitBackwards(u8, header_value, ",");
......@@ -84,8 +82,10 @@ pub const Headers = struct {
8482 const trimmed = std.mem.trim(u8, first, " ");
8583
8684 if (std.meta.stringToEnum(http.TransferEncoding, trimmed)) |te| {
85 if (headers.transfer_encoding != null) return error.HttpHeadersInvalid;
8786 headers.transfer_encoding = te;
8887 } else if (std.meta.stringToEnum(http.ContentEncoding, trimmed)) |ce| {
88 if (headers.transfer_compression != null) return error.HttpHeadersInvalid;
8989 headers.transfer_compression = ce;
9090 } else {
9191 return error.HttpTransferEncodingUnsupported;