From 52edd92dc042afa804c341a492dad508df81c52e Mon Sep 17 00:00:00 2001 From: uchenily Date: Mon, 24 Jun 2024 15:08:48 +0800 Subject: [PATCH] http: Add HttpResponse::status_text --- uvio/codec/http.hpp | 4 +++- uvio/net/http/http_protocol.hpp | 1 + uvio/net/http/http_server.hpp | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/uvio/codec/http.hpp b/uvio/codec/http.hpp index e579a58..73f7fc6 100644 --- a/uvio/codec/http.hpp +++ b/uvio/codec/http.hpp @@ -147,7 +147,9 @@ class HttpCodec : public Codec { -> Task> { // 对普通的 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) { diff --git a/uvio/net/http/http_protocol.hpp b/uvio/net/http/http_protocol.hpp index d26cb42..be60ffc 100644 --- a/uvio/net/http/http_protocol.hpp +++ b/uvio/net/http/http_protocol.hpp @@ -14,6 +14,7 @@ struct HttpRequest { struct HttpResponse { int status_code; + std::string status_text; http::HttpHeader headers; std::string body; }; diff --git a/uvio/net/http/http_server.hpp b/uvio/net/http/http_server.hpp index 009628f..e6698cd 100644 --- a/uvio/net/http/http_server.hpp +++ b/uvio/net/http/http_server.hpp @@ -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{