75 auto res = std::make_shared<http::response<http::string_body>>();
76 res->version(
req_.version());
77 res->keep_alive(
false);
79 std::string target(
req_.target());
80 std::string username = target.length() > 1 ? target.substr(1) :
"";
82 if (username.empty()) {
83 res->result(http::status::bad_request);
84 res->set(http::field::content_type,
"text/plain");
85 res->body() =
"Missing username in request URI.";
88 User user = User::fetch_github_user(username);
89 nlohmann::json json = {{
"login", user.
login},
93 res->result(http::status::ok);
94 res->set(http::field::content_type,
"application/json");
95 res->body() = json.dump();
96 }
catch (
const std::exception &e) {
97 res->result(http::status::not_found);
98 res->set(http::field::content_type,
"text/plain");
99 res->body() = std::string(
"Error fetching user: ") + e.what();
103 res->prepare_payload();
105 auto self = shared_from_this();
110 self->socket_.shutdown(tcp::socket::shutdown_send);
111 }
catch (
const boost::system::system_error &system_error) {
112 std::cerr <<
"Shutdown error: " << system_error.what() <<
'\n';