homebrew-core/Formula/cpp-httplib.rb

64 lines
1.7 KiB
Ruby

class CppHttplib < Formula
desc "C++ header-only HTTP/HTTPS server and client library"
homepage "https://github.com/yhirose/cpp-httplib"
url "https://github.com/yhirose/cpp-httplib/archive/refs/tags/v0.11.2.tar.gz"
sha256 "e620d030215733c4831fdc7813d5eb37a6fd599f8192a730662662e1748a741b"
license "MIT"
bottle do
sha256 cellar: :any_skip_relocation, all: "26be24755fd31d5fea75c8aa8789c637f9ea1cf6e5de8a43f79f1d775f2bca23"
end
depends_on "meson" => :build
depends_on "ninja" => :build
def install
system "meson", "build", *std_meson_args
system "meson", "compile", "-C", "build"
system "meson", "install", "-C", "build"
end
test do
(testpath/"server.cpp").write <<~CPP
#include <httplib.h>
using namespace httplib;
int main(void) {
Server svr;
svr.Get("/hi", [](const Request &, Response &res) {
res.set_content("Hello World!", "text/plain");
});
svr.listen("0.0.0.0", 8080);
}
CPP
(testpath/"client.cpp").write <<~CPP
#include <httplib.h>
#include <iostream>
using namespace httplib;
using namespace std;
int main(void) {
Client cli("localhost", 8080);
if (auto res = cli.Get("/hi")) {
cout << res->status << endl;
cout << res->get_header_value("Content-Type") << endl;
cout << res->body << endl;
return 0;
} else {
return 1;
}
}
CPP
system ENV.cxx, "server.cpp", "-I#{include}", "-lpthread", "-std=c++11", "-o", "server"
system ENV.cxx, "client.cpp", "-I#{include}", "-lpthread", "-std=c++11", "-o", "client"
fork do
exec "./server"
end
sleep 3
assert_match "Hello World!", shell_output("./client")
end
end