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:
parent
fb0bfe9631
commit
e68435ea9b
2 changed files with 12 additions and 4 deletions
|
@ -1 +1 @@
|
||||||
Hello from C++!
|
Hello from C++!!
|
||||||
|
|
|
@ -13,8 +13,8 @@ std::string read_html_file(const std::string& file_path) {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return "File not found: " + file_path;
|
return "File not found: " + file_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||||
|
file.close();
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +34,14 @@ int main() {
|
||||||
tcp::socket socket(io_context);
|
tcp::socket socket(io_context);
|
||||||
acceptor.accept(socket);
|
acceptor.accept(socket);
|
||||||
|
|
||||||
|
// static 17-byte string
|
||||||
|
|
||||||
// Read HTML content from a file (e.g., "index.html")
|
// 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
|
// Construct an HTTP response with the HTML content
|
||||||
http::response<http::string_body> response;
|
http::response<http::string_body> response;
|
||||||
|
@ -44,7 +50,9 @@ int main() {
|
||||||
response.reason("OK");
|
response.reason("OK");
|
||||||
response.set(http::field::server, "C++ Server");
|
response.set(http::field::server, "C++ Server");
|
||||||
response.set(http::field::content_type, "text/html");
|
response.set(http::field::content_type, "text/html");
|
||||||
response.body() = html_content;
|
|
||||||
|
// response.body() = html_content;
|
||||||
|
response.body() = msg;
|
||||||
response.prepare_payload();
|
response.prepare_payload();
|
||||||
|
|
||||||
// Send the response to the client
|
// Send the response to the client
|
||||||
|
|
Loading…
Add table
Reference in a new issue