Better verbose message.

The parsing of the request in the `RequestContext` constructor may be
buggy and make kiwix-serve crash.

If we print debug information only after the request is parsed, we will
never print the debug information if the parsing crash.

It is better to, at least, write that we've got a new request to avoid
us to try to debug previous request where everything were ok.
This commit is contained in:
Matthieu Gautier 2017-12-04 15:08:18 +00:00
parent aa9647e88c
commit 9a29874f9f
2 changed files with 11 additions and 7 deletions

View File

@ -724,17 +724,23 @@ static int accessHandlerCallback(void* cls,
size_t* upload_data_size, size_t* upload_data_size,
void** ptr) void** ptr)
{ {
if (isVerbose.load() ) {
printf("======================\n");
printf("Requesting : \n");
printf("full_url : %s\n", url);
}
RequestContext request(connection, rootLocation, url, method, version); RequestContext request(connection, rootLocation, url, method, version);
if (isVerbose.load() ) {
request.print_debug_info();
}
/* Unexpected method */ /* Unexpected method */
if (request.get_method() != RequestMethod::GET && request.get_method() != RequestMethod::POST) { if (request.get_method() != RequestMethod::GET && request.get_method() != RequestMethod::POST) {
printf("Reject request because of unhandled request method.\n");
printf("----------------------\n");
return MHD_NO; return MHD_NO;
} }
if (isVerbose.load()) {
printf("======================\n");
request.print_debug_info();
}
/* Prepare the variables */ /* Prepare the variables */
struct MHD_Response* response; struct MHD_Response* response;
request.httpResponseCode = request.has_range() ? MHD_HTTP_PARTIAL_CONTENT : MHD_HTTP_OK; request.httpResponseCode = request.has_range() ? MHD_HTTP_PARTIAL_CONTENT : MHD_HTTP_OK;

View File

@ -127,8 +127,6 @@ int RequestContext::fill_argument(void *__this, enum MHD_ValueKind kind,
} }
void RequestContext::print_debug_info() { void RequestContext::print_debug_info() {
printf("Requesting : \n");
printf("full_url : %s\n", full_url.c_str());
printf("method : %s (%d)\n", method==RequestMethod::GET ? "GET" : printf("method : %s (%d)\n", method==RequestMethod::GET ? "GET" :
method==RequestMethod::POST ? "POST" : method==RequestMethod::POST ? "POST" :
"OTHER", method); "OTHER", method);