Core: Added all well known http status codes (#195)

This commit is contained in:
Zbigniew Rębacz 2024-04-08 21:59:37 +02:00 committed by GitHub
parent 7b38e463df
commit fd1ea9a945
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 98 additions and 7 deletions

View file

@ -9,7 +9,7 @@ void ProcessHttpRequest(TcpSocket& client)
HttpHeader header;
if(!header.Read(client)) {
Cerr() << "Failed to read HttpHeader.\n";
HttpResponse(client, false, 400, "Invalid request");
HttpResponse(client, false, HttpStatus::BAD_REQUEST);
return;
}
@ -21,12 +21,15 @@ void ProcessHttpRequest(TcpSocket& client)
<< "Indonesia"
<< "Brazil"
<< "France";
HttpResponse(client, false, 200, "OK", "application/json", ja.ToString());
auto code = HttpStatus::OK;
HttpResponse(client, false, code, HttpStatus::ToString(code), "application/json",
ja.ToString());
return;
}
}
HttpResponse(client, false, 404, "Not found");
HttpResponse(client, false, HttpStatus::NOT_FOUND);
}
void RunServerLoop(TcpSocket& server)