| ... | @@ -420,13 +420,7 @@ pub const Response = struct { | ... | @@ -420,13 +420,7 @@ pub const Response = struct { |
| 420 | | 420 | |
| 421 | if (trailing) continue; | 421 | if (trailing) continue; |
| 422 | | 422 | |
| 423 | if (std.ascii.eqlIgnoreCase(header_name, "content-length")) { | 423 | if (std.ascii.eqlIgnoreCase(header_name, "transfer-encoding")) { |
| 424 | const content_length = std.fmt.parseInt(u64, header_value, 10) catch return error.InvalidContentLength; | | |
| 425 | | | |
| 426 | if (res.content_length != null and res.content_length != content_length) return error.HttpHeadersInvalid; | | |
| 427 | | | |
| 428 | res.content_length = content_length; | | |
| 429 | } else if (std.ascii.eqlIgnoreCase(header_name, "transfer-encoding")) { | | |
| 430 | // Transfer-Encoding: second, first | 424 | // Transfer-Encoding: second, first |
| 431 | // Transfer-Encoding: deflate, chunked | 425 | // Transfer-Encoding: deflate, chunked |
| 432 | var iter = mem.splitBackwardsScalar(u8, header_value, ','); | 426 | var iter = mem.splitBackwardsScalar(u8, header_value, ','); |
| ... | @@ -458,6 +452,12 @@ pub const Response = struct { | ... | @@ -458,6 +452,12 @@ pub const Response = struct { |
| 458 | } | 452 | } |
| 459 | | 453 | |
| 460 | if (iter.next()) |_| return error.HttpTransferEncodingUnsupported; | 454 | if (iter.next()) |_| return error.HttpTransferEncodingUnsupported; |
| | 455 | } else if (std.ascii.eqlIgnoreCase(header_name, "content-length")) { |
| | 456 | const content_length = std.fmt.parseInt(u64, header_value, 10) catch return error.InvalidContentLength; |
| | 457 | |
| | 458 | if (res.content_length != null and res.content_length != content_length) return error.HttpHeadersInvalid; |
| | 459 | |
| | 460 | res.content_length = content_length; |
| 461 | } else if (std.ascii.eqlIgnoreCase(header_name, "content-encoding")) { | 461 | } else if (std.ascii.eqlIgnoreCase(header_name, "content-encoding")) { |
| 462 | if (res.transfer_compression != null) return error.HttpHeadersInvalid; | 462 | if (res.transfer_compression != null) return error.HttpHeadersInvalid; |
| 463 | | 463 | |
| ... | @@ -658,17 +658,17 @@ pub const Request = struct { | ... | @@ -658,17 +658,17 @@ pub const Request = struct { |
| 658 | .none => {}, | 658 | .none => {}, |
| 659 | } | 659 | } |
| 660 | } else { | 660 | } else { |
| 661 | if (has_content_length) { | 661 | if (has_transfer_encoding) { |
| 662 | const content_length = std.fmt.parseInt(u64, req.headers.getFirstValue("content-length").?, 10) catch return error.InvalidContentLength; | | |
| 663 | | | |
| 664 | req.transfer_encoding = .{ .content_length = content_length }; | | |
| 665 | } else if (has_transfer_encoding) { | | |
| 666 | const transfer_encoding = req.headers.getFirstValue("transfer-encoding").?; | 662 | const transfer_encoding = req.headers.getFirstValue("transfer-encoding").?; |
| 667 | if (std.mem.eql(u8, transfer_encoding, "chunked")) { | 663 | if (std.mem.eql(u8, transfer_encoding, "chunked")) { |
| 668 | req.transfer_encoding = .chunked; | 664 | req.transfer_encoding = .chunked; |
| 669 | } else { | 665 | } else { |
| 670 | return error.UnsupportedTransferEncoding; | 666 | return error.UnsupportedTransferEncoding; |
| 671 | } | 667 | } |
| | 668 | } else if (has_content_length) { |
| | 669 | const content_length = std.fmt.parseInt(u64, req.headers.getFirstValue("content-length").?, 10) catch return error.InvalidContentLength; |
| | 670 | |
| | 671 | req.transfer_encoding = .{ .content_length = content_length }; |
| 672 | } else { | 672 | } else { |
| 673 | req.transfer_encoding = .none; | 673 | req.transfer_encoding = .none; |
| 674 | } | 674 | } |