commit 24c27acbf4be5ebfb6b64cd7697facc9219c500f from: Aleksey Ryndin date: Fri Aug 11 15:54:30 2023 UTC Empty meta on successfully response commit - 50eb955cfb20f96fd59942b27e83fe533e1a3fcc commit + 24c27acbf4be5ebfb6b64cd7697facc9219c500f blob - 6e2205ba496a0fb0ece746868d149c26fdae1681 blob + 05c0100fbe7c3827ea489de80b145de1e22516ff --- vostokd/vostokd.cc +++ vostokd/vostokd.cc @@ -18,17 +18,19 @@ namespace vostok namespace { + +/** Remove null terminating character and return as span */ template -constexpr std::span literal_to_span(const char (&arr)[N]) +constexpr std::span cut_null(const char (&arr)[N]) { static_assert(N > 0); return std::span{&arr[0], N - 1}; } + namespace meta { -const auto badrequest = literal_to_span("Bad request"); -const auto textgemini = literal_to_span("text/gemini"); +const auto badrequest = cut_null("Bad request"); } // namespace meta @@ -111,9 +113,10 @@ void client_thread(transport::accepted_context::value std::array buffer; const auto url = transport::read_request(ctx.get_ctx(), buffer); + error::g_log << "Requested URL: \""; for (auto c : url) error::g_log << c; - error::g_log << std::endl; + error::g_log << "\"" << std::endl; if (!url.size()) { @@ -121,9 +124,10 @@ void client_thread(transport::accepted_context::value return; } - transport::send_response(ctx.get_ctx(), transport::STATUS_20_SUCCESS, meta::textgemini); - const char content[] = "# Vostok server\r\n\r\n...work-in-progress..."; - transport::send(ctx.get_ctx(), literal_to_span(content)); + // > If is an empty string, the MIME type MUST default to "text/gemini; charset=utf-8". + transport::send_response(ctx.get_ctx(), transport::STATUS_20_SUCCESS, std::span{}); + static const char content[] = "# Vostok server\r\n\r\n...work-in-progress..."; + transport::send(ctx.get_ctx(), cut_null(content)); }