mirror of
https://github.com/cesanta/mongoose.git
synced 2025-01-15 02:08:08 +08:00
Fix #1292 - allow requests with missing protocol version, responses with no reason fields
This commit is contained in:
parent
e69de57def
commit
886a29d659
@ -620,8 +620,8 @@ int mg_http_parse(const char *s, size_t len, struct mg_http_message *hm) {
|
||||
s = skip(s, end, " ", &hm->uri);
|
||||
s = skip(s, end, "\r\n", &hm->proto);
|
||||
|
||||
// Sanity check
|
||||
if (hm->method.len == 0 || hm->uri.len == 0 || hm->proto.len == 0) return -1;
|
||||
// Sanity check. Allow protocol/reason to be empty
|
||||
if (hm->method.len == 0 || hm->uri.len == 0) return -1;
|
||||
|
||||
// If URI contains '?' character, setup query string
|
||||
if ((qs = (const char *) memchr(hm->uri.ptr, '?', hm->uri.len)) != NULL) {
|
||||
|
@ -209,8 +209,8 @@ int mg_http_parse(const char *s, size_t len, struct mg_http_message *hm) {
|
||||
s = skip(s, end, " ", &hm->uri);
|
||||
s = skip(s, end, "\r\n", &hm->proto);
|
||||
|
||||
// Sanity check
|
||||
if (hm->method.len == 0 || hm->uri.len == 0 || hm->proto.len == 0) return -1;
|
||||
// Sanity check. Allow protocol/reason to be empty
|
||||
if (hm->method.len == 0 || hm->uri.len == 0) return -1;
|
||||
|
||||
// If URI contains '?' character, setup query string
|
||||
if ((qs = (const char *) memchr(hm->uri.ptr, '?', hm->uri.len)) != NULL) {
|
||||
|
@ -344,6 +344,8 @@ static void eh1(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
mg_http_reply(c, 200, "", "%.*s", (int) hm->body.len, hm->body.ptr);
|
||||
} else if (mg_http_match_uri(hm, "/bar")) {
|
||||
mg_http_reply(c, 404, "", "not found");
|
||||
} else if (mg_http_match_uri(hm, "/no_reason")) {
|
||||
mg_printf(c, "%s", "HTTP/1.0 200\r\nContent-Length: 2\r\n\r\nok");
|
||||
} else if (mg_http_match_uri(hm, "/badroot")) {
|
||||
struct mg_http_serve_opts sopts = {"/BAAADDD!", NULL, NULL};
|
||||
mg_http_serve_dir(c, hm, &sopts);
|
||||
@ -473,6 +475,10 @@ static void test_http_server(void) {
|
||||
ASSERT(fetch(&mgr, buf, url, "GET /%%61.txt HTTP/1.0\n\n") == 200);
|
||||
ASSERT(cmpbody(buf, "hello\n") == 0);
|
||||
|
||||
// Responses with missing reason phrase must also work
|
||||
ASSERT(fetch(&mgr, buf, url, "GET /no_reason HTTP/1.0\n\n") == 200);
|
||||
ASSERT(cmpbody(buf, "ok") == 0);
|
||||
|
||||
{
|
||||
extern char *mg_http_etag(char *, size_t, mg_stat_t *);
|
||||
char etag[100];
|
||||
@ -862,7 +868,7 @@ static void test_http_parse(void) {
|
||||
const char *s = "a b c\n\n";
|
||||
ASSERT(mg_http_parse(s, strlen(s), &hm) == (int) strlen(s));
|
||||
s = "a b\nc\n\n";
|
||||
ASSERT(mg_http_parse(s, strlen(s), &hm) < 0);
|
||||
ASSERT(mg_http_parse(s, strlen(s), &hm) == (int) strlen(s));
|
||||
s = "a\nb\nc\n\n";
|
||||
ASSERT(mg_http_parse(s, strlen(s), &hm) < 0);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user