Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/os.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ function(os_add_executable TARGET NAME)
${INCLUDEOS_PACKAGE}/lib/libos.a
${INCLUDEOS_PACKAGE}/libcxx/lib/libc++.a
${INCLUDEOS_PACKAGE}/libc/lib/libc.a
${INCLUDEOS_PACKAGE}/http-parser/lib/libhttp_parser.a
${INCLUDEOS_PACKAGE}/lib/libmusl_syscalls.a
${INCLUDEOS_PACKAGE}/libunwind/lib/libunwind.a
${INCLUDEOS_PACKAGE}/libgcc/lib/linux/${LIBGCC}
Expand Down
23 changes: 0 additions & 23 deletions deps/http-parser/default.nix

This file was deleted.

5 changes: 2 additions & 3 deletions overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ final: prev: {
# Deps
botan2 = self.callPackage ./deps/botan/default.nix { };
libfmt = self.callPackage ./deps/libfmt/default.nix { };
http-parser = self.callPackage ./deps/http-parser/default.nix { };
s2n-tls = self.callPackage ./deps/s2n/default.nix { };
uzlib = self.callPackage ./deps/uzlib/default.nix { };

Expand Down Expand Up @@ -161,7 +160,7 @@ final: prev: {
buildInputs = [
self.libfmt
self.botan2
self.http-parser
prev.pkgsStatic.http-parser
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yippie!

prev.pkgsStatic.openssl
prev.pkgsStatic.rapidjson
#self.s2n-tls 👈 This is postponed until we can fix the s2n build.
Expand All @@ -179,6 +178,7 @@ final: prev: {
cp -r -v ${final.stdenvIncludeOS.libraries.libcxx.include} $out/libcxx/include
cp -r -v ${final.stdenvIncludeOS.libraries.libunwind} $out/libunwind
cp -r -v ${final.stdenvIncludeOS.libraries.libgcc} $out/libgcc
cp -r -v ${final.pkgsStatic.http-parser} $out/http-parser
'';

archFlags = if self.stdenv.targetPlatform.system == "i686-linux" then
Expand Down Expand Up @@ -206,7 +206,6 @@ final: prev: {

passthru = {
inherit (self) uzlib;
inherit (self) http-parser;
inherit (self) botan2;
inherit (self) libfmt;
#inherit (self) s2n-tls;
Expand Down
2 changes: 1 addition & 1 deletion test/integration/net/http/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void Service::ready()
printf("Error: %s \n", err.to_string().c_str());

CHECKSERT(!err, "No error");
printf("Received body: %s\n", res->body());
printf("Received body: %.*s\n", static_cast<int>(res->body().length()), res->body().data());
Copy link
Contributor

@mazunki mazunki Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not using the opportunity to replace printf-specifiers with {}?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn pirkete.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would that look like?

Copy link
Contributor

@mazunki mazunki Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this specific case, I see that res->body() returns util::sview, an alias for std::string_view: a type which is aware of its own size.

In C++23, we'd be able to std::println("{}", res->body());. Super convenient.

In C++20, you can either

std::cout << std::body() << std::endl; 

// or if you want to use printf
auto s = std::format("{}", res->body());
printf("%s\n", s.cstr());

It's worth noting that if res->body() wasn't a string_view alias, but something else like http::ResponseBody that wasn't a direct subtype of std::string, we'd have to implement (C++23):

namespace http {
    inline std::string format_as(const http::ResponseBody& body) {
        return body.toString();
    }
}

For C++20, this requires building a template for std::formatter<ResponseBody, char> with parse() and format() which I personally would rather avoid as it's a bunch of boilerplate. Happily C++23 makes it rather easy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, for completeness sake, in case you actually need to specify the length:

size_t len = body.length();
char *s = body.data();  // this loses the size() knowledge

std::cout << std::format("{:{}}\n", s, len);

CHECKSERT(res->body() == "/testing", "Received body: \"/testing\"");

printf("SUCCESS\n");
Expand Down
2 changes: 1 addition & 1 deletion test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ exclusions=(
"dhcpd" # Times out, requires certain routes to be set up. Seems easy.
"dhcpd_dhclient_linux" # We can't run userspace tests with this setup yet.
"gateway" # Requires NaCl which is currently not integrated
"http" # Linking fails, undefined ref to http_parser_parse_url, http_parser_execute
"microLB" # Missing dependencies: microLB, diskbuilder, os_add_os_library
"nat" # Times out after 3 / 6 tests seem to pass. Might be a legit bug here.
"router" # Times out, requies sudo and has complex network setup.
Expand All @@ -258,6 +257,7 @@ unsandbox_list=(
"${INTEGRATION_TESTS}/net/tcp"
"${INTEGRATION_TESTS}/net/udp"
"${INTEGRATION_TESTS}/net/dns" # except this one which times out instead
"${INTEGRATION_TESTS}/net/http"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

)
run_testsuite "${INTEGRATION_TESTS}/net" "${exclusions[@]}"
unsandbox_list=()
Expand Down