Skip to content

Commit

Permalink
http: Add HttpResponse::status_text
Browse files Browse the repository at this point in the history
  • Loading branch information
uchenily committed Jun 24, 2024
1 parent cf38c50 commit 52edd92
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion uvio/codec/http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ class HttpCodec : public Codec<HttpCodec> {
-> Task<Result<void>> {
// 对普通的 HTTP 请求的响应
if (auto ret = co_await writer.write(
std::format("HTTP/1.0 200 OK\r\nContent-Length: {}\r\n\r\n{}",
std::format("HTTP/1.0 {} {}\r\nContent-Length: {}\r\n\r\n{}",
resp.status_code,
resp.status_text,
resp.body.size(),
resp.body));
!ret) {
Expand Down
1 change: 1 addition & 0 deletions uvio/net/http/http_protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct HttpRequest {

struct HttpResponse {
int status_code;
std::string status_text;
http::HttpHeader headers;
std::string body;
};
Expand Down
2 changes: 2 additions & 0 deletions uvio/net/http/http_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ class HttpServer {
it != map_handles_.end()) {
co_await it->second(request, resp);
resp.status_code = 200;
resp.status_text = "OK";
} else {
// TODO(x)
resp.body = "Page not found";
resp.status_code = 404;
resp.status_text = "Not Found";
}

// HttpResponse resp{
Expand Down

0 comments on commit 52edd92

Please sign in to comment.