MXS-1220: Expand HttpResponse class
The class now generates default headers. The ETag and Last-Modified tags do not represent any actual modification time or resource hash. The basic functionality of the HTTP responses is tested by the core test suite. More advanced testing of the whole REST API is still required. Removed the static `create` functions as only the JSON parsing version could generated errors and even then the errors were unlikely. By replacing the static creator function with a normal constructor, the HttpResponse class can now also be created on the stack making its use easier.
This commit is contained in:
committed by
Markus Mäkelä
parent
a73d3e9276
commit
9d0d394361
@ -12,6 +12,7 @@
|
||||
*/
|
||||
|
||||
#include "../maxscale/httprequest.hh"
|
||||
#include "../maxscale/httpresponse.hh"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
@ -306,6 +307,23 @@ int test_message_body()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_response()
|
||||
{
|
||||
TEST(HttpResponse().get_response().find("200 OK") != string::npos,
|
||||
"Default constructor should return a 200 OK with no body");
|
||||
TEST(HttpResponse("Test").get_response().find("\r\n\r\nTest") != string::npos,
|
||||
"Custom payload should be found in the response");
|
||||
TEST(HttpResponse("", HTTP_204_NO_CONTENT).get_response().find("204 No Content") != string::npos,
|
||||
"Using custom header should generate correct response");
|
||||
|
||||
HttpResponse response("A Bad gateway", HTTP_502_BAD_GATEWAY);
|
||||
TEST(response.get_response().find("\r\n\r\nA Bad gateway") != string::npos &&
|
||||
response.get_response().find("502 Bad Gateway") != string::npos,
|
||||
"Both custom response body and return code should be found");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int rc = 0;
|
||||
@ -313,6 +331,7 @@ int main(int argc, char** argv)
|
||||
rc += test_basic();
|
||||
rc += test_headers();
|
||||
rc += test_message_body();
|
||||
rc += test_response();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user