mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 05:20:21 +00:00
Fix ParseHttpMessage failing to store >2 repeatable headers (#657)
This commit is contained in:
parent
e557058ac8
commit
84b9b8ed87
2 changed files with 31 additions and 4 deletions
|
@ -236,8 +236,12 @@ int ParseHttpMessage(struct HttpMessage *r, const char *p, size_t n) {
|
||||||
unsigned c2;
|
unsigned c2;
|
||||||
struct HttpHeader *p1, *p2;
|
struct HttpHeader *p1, *p2;
|
||||||
p1 = r->xheaders.p;
|
p1 = r->xheaders.p;
|
||||||
c2 = r->xheaders.c + 2;
|
c2 = r->xheaders.c;
|
||||||
c2 = c2 >> 1;
|
if (c2 == 0) {
|
||||||
|
c2 = 1;
|
||||||
|
} else {
|
||||||
|
c2 = c2 * 2;
|
||||||
|
}
|
||||||
if ((p2 = realloc(p1, c2 * sizeof(*p1)))) {
|
if ((p2 = realloc(p1, c2 * sizeof(*p1)))) {
|
||||||
r->xheaders.p = p2;
|
r->xheaders.p = p2;
|
||||||
r->xheaders.c = c2;
|
r->xheaders.c = c2;
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/intrin/bits.h"
|
|
||||||
#include "libc/errno.h"
|
#include "libc/errno.h"
|
||||||
|
#include "libc/intrin/bits.h"
|
||||||
#include "libc/log/check.h"
|
#include "libc/log/check.h"
|
||||||
#include "libc/mem/mem.h"
|
|
||||||
#include "libc/mem/gc.internal.h"
|
#include "libc/mem/gc.internal.h"
|
||||||
|
#include "libc/mem/mem.h"
|
||||||
#include "libc/stdio/stdio.h"
|
#include "libc/stdio/stdio.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/testlib/ezbench.h"
|
#include "libc/testlib/ezbench.h"
|
||||||
|
@ -245,6 +245,29 @@ Content-Type: text/plain\r\n\
|
||||||
ASSERT_EQ(0, req->xheaders.n);
|
ASSERT_EQ(0, req->xheaders.n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(ParseHttpMessage, testCommaSeparatedOnMultipleLines_manyLines) {
|
||||||
|
static const char m[] = "\
|
||||||
|
GET / HTTP/1.1\r\n\
|
||||||
|
Accept: text/html\r\n\
|
||||||
|
Accept: text/plain\r\n\
|
||||||
|
Accept: text/csv\r\n\
|
||||||
|
Accept: text/xml\r\n\
|
||||||
|
Accept: text/css\r\n\
|
||||||
|
\r\n";
|
||||||
|
InitHttpMessage(req, kHttpRequest);
|
||||||
|
EXPECT_EQ(strlen(m), ParseHttpMessage(req, m, strlen(m)));
|
||||||
|
EXPECT_STREQ("text/html", gc(slice(m, req->headers[kHttpAccept])));
|
||||||
|
ASSERT_EQ(4, req->xheaders.n);
|
||||||
|
EXPECT_STREQ("Accept", gc(slice(m, req->xheaders.p[0].k)));
|
||||||
|
EXPECT_STREQ("text/plain", gc(slice(m, req->xheaders.p[0].v)));
|
||||||
|
EXPECT_STREQ("Accept", gc(slice(m, req->xheaders.p[1].k)));
|
||||||
|
EXPECT_STREQ("text/csv", gc(slice(m, req->xheaders.p[1].v)));
|
||||||
|
EXPECT_STREQ("Accept", gc(slice(m, req->xheaders.p[2].k)));
|
||||||
|
EXPECT_STREQ("text/xml", gc(slice(m, req->xheaders.p[2].v)));
|
||||||
|
EXPECT_STREQ("Accept", gc(slice(m, req->xheaders.p[3].k)));
|
||||||
|
EXPECT_STREQ("text/css", gc(slice(m, req->xheaders.p[3].v)));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(ParseHttpMessage, testCommaSeparatedOnMultipleLines_becomesLinear) {
|
TEST(ParseHttpMessage, testCommaSeparatedOnMultipleLines_becomesLinear) {
|
||||||
static const char m[] = "\
|
static const char m[] = "\
|
||||||
GET / HTTP/1.1\r\n\
|
GET / HTTP/1.1\r\n\
|
||||||
|
|
Loading…
Add table
Reference in a new issue