Skip to content

Conversation

@MagnusS
Copy link
Member

@MagnusS MagnusS commented Oct 29, 2025

  • Fix compilation issue with printf and stringview. Printf has to know the
    length as stringview may not be null-terminated.
  • Use latest http-parser from nixpkgs as it now supports static builds
  • Include libhttp-parser.a in IncludeOS library
  • Enable http test (which now works again)

Fix compilation issue with printf and stringview. Printf has to know the
length as stringview may not be null-terminated.
- Use latest http-parser from nixpkgs as it now supports static builds
- Include libhttp-parser.a in IncludeOS library
- Enable http test (which now works again)
@MagnusS MagnusS changed the title Re-enable http test Fix http linking and re-enable http test Oct 29, 2025
@MagnusS MagnusS changed the title Fix http linking and re-enable http test Fix http linking and enable http test Oct 29, 2025
@torgeiru
Copy link
Contributor

🌈 All tests are passing 🌈 except for the known flaky DNS test


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);

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!

"${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!

Copy link

@alfreb-scalemem alfreb-scalemem left a comment

Choose a reason for hiding this comment

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

Nice!!

@alfreb alfreb merged commit fde0b48 into includeos:main Nov 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants