-
Notifications
You must be signed in to change notification settings - Fork 387
Fix http linking and enable http test #2353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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)
|
🌈 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()); |
There was a problem hiding this comment.
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 {}?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn pirkete.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
alfreb-scalemem
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!!
length as stringview may not be null-terminated.