64 lines
1.7 KiB
Ruby
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.3.tar.gz"
|
|
sha256 "799b2daa0441d207f6cd1179ae3a34869722084a434da6614978be1682c1e12d"
|
|
license "MIT"
|
|
|
|
bottle do
|
|
sha256 cellar: :any_skip_relocation, all: "a8e77a0a4aeb29b9a9f0eb4419bb188dd157dfafa64c5f7d32aad521d1729d60"
|
|
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
|