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