MXS-1220: Add HEAD method support
The HEAD method was not in the list of supported methods.
This commit is contained in:
committed by
Markus Mäkelä
parent
c937457738
commit
55b52b8ab1
@ -28,7 +28,8 @@ enum http_verb
|
||||
HTTP_PUT,
|
||||
HTTP_POST,
|
||||
HTTP_OPTIONS,
|
||||
HTTP_PATCH
|
||||
HTTP_PATCH,
|
||||
HTTP_HEAD
|
||||
};
|
||||
|
||||
/** Possible HTTP return codes */
|
||||
@ -101,6 +102,10 @@ static inline enum http_verb string_to_http_verb(string& verb)
|
||||
{
|
||||
return HTTP_OPTIONS;
|
||||
}
|
||||
else if (verb == "HEAD")
|
||||
{
|
||||
return HTTP_HEAD;
|
||||
}
|
||||
|
||||
return HTTP_UNKNOWN;
|
||||
}
|
||||
@ -126,6 +131,8 @@ static inline const char* http_verb_to_string(enum http_verb verb)
|
||||
return "PATCH";
|
||||
case HTTP_OPTIONS:
|
||||
return "OPTIONS";
|
||||
case HTTP_HEAD:
|
||||
return "HEAD";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@ const char* verbs_pass[] =
|
||||
"POST",
|
||||
"OPTIONS",
|
||||
"PATCH",
|
||||
"HEAD",
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -264,12 +265,23 @@ const char* body_fail[] =
|
||||
NULL
|
||||
};
|
||||
|
||||
const char* body_verbs_pass[] =
|
||||
{
|
||||
"PUT",
|
||||
"POST",
|
||||
"PATCH",
|
||||
NULL
|
||||
};
|
||||
|
||||
int test_message_body()
|
||||
{
|
||||
for (int i = 0; body_pass[i]; i++)
|
||||
{
|
||||
for (int j = 0; body_verbs_pass[j]; j++)
|
||||
{
|
||||
/** Only PUT/POST/PATCH methods should have request bodies */
|
||||
stringstream ss;
|
||||
ss << "GET / HTTP/1.1\r\n\r\n" << body_pass[i];
|
||||
ss << body_verbs_pass[j] << " / HTTP/1.1\r\n\r\n" << body_pass[i];
|
||||
SHttpRequest parser(HttpRequest::parse(ss.str()));
|
||||
TEST(parser.get() != NULL, "Valid request body should be parsed: %s",
|
||||
ss.str().c_str());
|
||||
@ -277,15 +289,19 @@ int test_message_body()
|
||||
TEST(parser->get_json_str() == body_pass[i], "Body value should be correct: %s",
|
||||
parser->get_json_str().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; body_pass[i]; i++)
|
||||
{
|
||||
for (int j = 0; verbs_pass[j]; j++)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "GET / HTTP/1.1\r\n\r\n" << body_fail[i];
|
||||
ss << verbs_pass[j] << " / HTTP/1.1\r\n\r\n" << body_fail[i];
|
||||
SHttpRequest parser(HttpRequest::parse(ss.str()));
|
||||
TEST(parser.get() == NULL, "Invalid request body should not be parsed: %s",
|
||||
ss.str().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user