Skip to content
This repository was archived by the owner on Jun 30, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include <sys/types.h>
#endif

#include "evhtp/config.h"
#include "internal.h"
#include "evhtp/parser.h"
#include "evhtp/config.h"

#if '\n' != '\x0a' || 'A' != 65
#error "You have somehow found a non-ASCII host. We can't build here."
Expand All @@ -36,6 +36,7 @@ enum parser_flags {
parser_flag_connection_keep_alive = (1 << 1),
parser_flag_connection_close = (1 << 2),
parser_flag_trailing = (1 << 3),
parser_flag_have_content_length = (1 << 4),
};

enum parser_state {
Expand Down Expand Up @@ -1814,6 +1815,7 @@ htparser_run(htparser * p, htparse_hooks * hooks, const char * data, size_t len)
p->error = htparse_error_too_big;
return i + 1;
}
p->flags |= parser_flag_have_content_length;

break;
case eval_hdr_val_connection:
Expand Down Expand Up @@ -2028,8 +2030,22 @@ htparser_run(htparser * p, htparse_hooks * hooks, const char * data, size_t len)
p->state = s_body_read;
} else if (p->content_len == 0)
{
res = hook_on_msg_complete_run(p, hooks);
p->state = s_start;
if (p->flags & parser_flag_have_content_length)
{
res = hook_on_msg_complete_run(p, hooks);
p->state = s_start;
}else{
if(i + 1 < len)
{
p->content_len = len - i - 1;
p->state = s_body_read;
}
else
{
res = hook_on_msg_complete_run(p, hooks);
p->state = s_start;
}
}
} else {
p->state = s_hdrline_done;
}
Expand Down Expand Up @@ -2072,8 +2088,23 @@ htparser_run(htparser * p, htparse_hooks * hooks, const char * data, size_t len)
i--;
} else if (p->content_len == 0)
{
res = hook_on_msg_complete_run(p, hooks);
p->state = s_start;
if (p->flags & parser_flag_have_content_length)
{
res = hook_on_msg_complete_run(p, hooks);
p->state = s_start;
}else{
if(i < len)
{
p->content_len = len - i;
p->state = s_body_read;
i--;
}
else
{
res = hook_on_msg_complete_run(p, hooks);
p->state = s_start;
}
}
}

if (res)
Expand Down