1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 23:24:09 +00:00

static 17-byte string

This commit is contained in:
Matheus Catarino França 2023-08-21 09:01:16 -03:00
parent fb0bfe9631
commit e68435ea9b
2 changed files with 12 additions and 4 deletions

View file

@ -1 +1 @@
Hello from C++!
Hello from C++!!

View file

@ -13,8 +13,8 @@ std::string read_html_file(const std::string& file_path) {
if (!file) {
return "File not found: " + file_path;
}
std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
file.close();
return content;
}
@ -34,8 +34,14 @@ int main() {
tcp::socket socket(io_context);
acceptor.accept(socket);
// static 17-byte string
// Read HTML content from a file (e.g., "index.html")
std::string html_content = read_html_file("hello.html");
// std::string html_content = read_html_file("hello.html");
// or
std::string msg = "Hello from C++!!!";
// std::cout << "str len: " << (html_content.length() == msg.length()) << std::boolalpha << "\n";
// Construct an HTTP response with the HTML content
http::response<http::string_body> response;
@ -44,7 +50,9 @@ int main() {
response.reason("OK");
response.set(http::field::server, "C++ Server");
response.set(http::field::content_type, "text/html");
response.body() = html_content;
// response.body() = html_content;
response.body() = msg;
response.prepare_payload();
// Send the response to the client