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 {...@@ -74,8 +74,6 @@ pub const Headers = struct {
74 if (headers.content_length != null) return error.HttpHeadersInvalid;74 if (headers.content_length != null) return error.HttpHeadersInvalid;
75 headers.content_length = try std.fmt.parseInt(u64, header_value, 10);75 headers.content_length = try std.fmt.parseInt(u64, header_value, 10);
76 } else if (std.ascii.eqlIgnoreCase(header_name, "transfer-encoding")) {76 } else if (std.ascii.eqlIgnoreCase(header_name, "transfer-encoding")) {
77 if (headers.transfer_encoding != null or headers.transfer_compression != null) return error.HttpHeadersInvalid;
78
79 // Transfer-Encoding: second, first77 // Transfer-Encoding: second, first
80 // Transfer-Encoding: deflate, chunked78 // Transfer-Encoding: deflate, chunked
81 var iter = std.mem.splitBackwards(u8, header_value, ",");79 var iter = std.mem.splitBackwards(u8, header_value, ",");
...@@ -84,8 +82,10 @@ pub const Headers = struct {...@@ -84,8 +82,10 @@ pub const Headers = struct {
84 const trimmed = std.mem.trim(u8, first, " ");82 const trimmed = std.mem.trim(u8, first, " ");
8583
86 if (std.meta.stringToEnum(http.TransferEncoding, trimmed)) |te| {84 if (std.meta.stringToEnum(http.TransferEncoding, trimmed)) |te| {
85 if (headers.transfer_encoding != null) return error.HttpHeadersInvalid;
87 headers.transfer_encoding = te;86 headers.transfer_encoding = te;
88 } else if (std.meta.stringToEnum(http.ContentEncoding, trimmed)) |ce| {87 } else if (std.meta.stringToEnum(http.ContentEncoding, trimmed)) |ce| {
88 if (headers.transfer_compression != null) return error.HttpHeadersInvalid;
89 headers.transfer_compression = ce;89 headers.transfer_compression = ce;
90 } else {90 } else {
91 return error.HttpTransferEncodingUnsupported;91 return error.HttpTransferEncodingUnsupported;