std.http: header whitespace is optional, and not part of value

This commit is contained in:
Nameless 2024-02-26 09:53:48 -06:00
parent 69bcdbefd0
commit 81713f20a6
No known key found for this signature in database
GPG key ID: A477BC03CAFCCAF7
3 changed files with 6 additions and 6 deletions

View file

@ -489,9 +489,9 @@ pub const Response = struct {
else => {},
}
var line_it = mem.splitSequence(u8, line, ": ");
var line_it = mem.splitScalar(u8, line, ':');
const header_name = line_it.next().?;
const header_value = line_it.rest();
const header_value = mem.trim(u8, line_it.rest(), " \t");
if (header_name.len == 0) return error.HttpHeadersInvalid;
if (std.ascii.eqlIgnoreCase(header_name, "connection")) {

View file

@ -48,7 +48,7 @@ pub fn next(it: *HeaderIterator) ?std.http.Header {
}
test next {
var it = HeaderIterator.init("200 OK\r\na: b\r\nc: \r\nd: e\r\n\r\nf: g\r\n\r\n");
var it = HeaderIterator.init("200 OK\r\na: b\r\nc: \r\nd:e\r\n\r\nf: g\r\n\r\n");
try std.testing.expect(!it.is_trailer);
{
const header = it.next().?;
@ -80,7 +80,7 @@ test next {
try std.testing.expect(!it.is_trailer);
try std.testing.expectEqual(null, it.next());
it = HeaderIterator.init("200 OK\r\na: b\r\n\r\n: ss\r\n\r\n");
it = HeaderIterator.init("200 OK\r\na:b\r\n\r\n: ss\r\n\r\n");
try std.testing.expect(!it.is_trailer);
{
const header = it.next().?;

View file

@ -211,9 +211,9 @@ pub const Request = struct {
else => {},
}
var line_it = mem.splitSequence(u8, line, ": ");
var line_it = mem.splitScalar(u8, line, ':');
const header_name = line_it.next().?;
const header_value = line_it.rest();
const header_value = mem.trim(u8, line_it.rest(), " \t");
if (header_name.len == 0) return error.HttpHeadersInvalid;
if (std.ascii.eqlIgnoreCase(header_name, "connection")) {