From 1670588dd487b1781d1315859a00deb303526e33 Mon Sep 17 00:00:00 2001 From: Chen Bo Date: Mon, 17 Jul 2023 19:50:36 +0800 Subject: [PATCH] Fix HTTP header parse for space --- net/http/headers.cpp | 3 ++- net/http/parser.h | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/net/http/headers.cpp b/net/http/headers.cpp index 459b30cb..de85a649 100644 --- a/net/http/headers.cpp +++ b/net/http/headers.cpp @@ -170,7 +170,8 @@ int HeadersBase::parse() { Parser p({m_buf, m_buf_size}); while(p[0] != '\r') { auto k = p.extract_until_char(':'); - p.skip_string(": "); + p.skip_chars(':'); + p.skip_chars(' ', true); auto v = p.extract_until_char('\r'); p.skip_string("\r\n"); if (kv_add({k, v}) == nullptr) diff --git a/net/http/parser.h b/net/http/parser.h index 304c46f7..edb277e5 100644 --- a/net/http/parser.h +++ b/net/http/parser.h @@ -32,9 +32,13 @@ class Parser { { if (estring_view(_ptr, _end - _ptr).starts_with(sv)) _ptr += sv.length(); } - void skip_chars(char c) + void skip_chars(char c, bool continuously = false) { - if (*_ptr == c) _ptr++; + while (*_ptr == c) { + _ptr++; + if (!continuously) + return; + } } void skip_until_string(const std::string& s) {