[wpiutil] Upgrade to fmt 10.2.1, add wpi::print (#6161)

We now use a wrapper (wpi::print) to catch exceptions since we can't patch
std::print() to not throw when we ultimately migrate to it.

fmtlib and std format/print throw the same exceptions and always have. We previously patched fmt::print() to not throw a write failure exception, but we can't do that for std::print(); wpi::print() is the migration plan.
This commit is contained in:
Tyler Veness
2024-05-12 06:25:42 -07:00
committed by GitHub
parent 6c9dcc157e
commit d88c71ffdc
99 changed files with 1374 additions and 1130 deletions

View File

@@ -4,12 +4,12 @@
#include "wpinet/HttpServerConnection.h"
#include <fmt/format.h>
#include <wpi/SmallString.h>
#include <wpi/SmallVector.h>
#include <wpi/SpanExtras.h>
#include <wpi/StringExtras.h>
#include <wpi/fmt/raw_ostream.h>
#include <wpi/print.h>
#include "wpinet/raw_uv_ostream.h"
@@ -65,7 +65,7 @@ void HttpServerConnection::BuildHeader(raw_ostream& os, int code,
std::string_view contentType,
uint64_t contentLength,
std::string_view extra) {
fmt::print(os, "HTTP/{}.{} {} {}\r\n", m_request.GetMajor(),
wpi::print(os, "HTTP/{}.{} {} {}\r\n", m_request.GetMajor(),
m_request.GetMinor(), code, codeText);
if (contentLength == 0) {
m_keepAlive = false;
@@ -76,7 +76,7 @@ void HttpServerConnection::BuildHeader(raw_ostream& os, int code,
BuildCommonHeaders(os);
os << "Content-Type: " << contentType << "\r\n";
if (contentLength != 0) {
fmt::print(os, "Content-Length: {}\r\n", contentLength);
wpi::print(os, "Content-Length: {}\r\n", contentLength);
}
os << "Access-Control-Allow-Origin: *\r\nAccess-Control-Allow-Methods: *\r\n";
if (!extra.empty()) {

View File

@@ -9,11 +9,11 @@
#include <string>
#include <string_view>
#include <fmt/format.h>
#include <wpi/Base64.h>
#include <wpi/SmallString.h>
#include <wpi/SmallVector.h>
#include <wpi/StringExtras.h>
#include <wpi/print.h>
#include <wpi/raw_ostream.h>
#include <wpi/sha1.h>
@@ -714,7 +714,7 @@ static void VerboseDebug(const WebSocket::Frame& frame) {
str.append(std::string_view(d.base, d.len));
}
#endif
fmt::print("WS SendText({})\n", str.str());
wpi::print("WS SendText({})\n", str.str());
} else if ((frame.opcode & 0x7f) == 0x02) {
SmallString<128> str;
#ifdef WPINET_WEBSOCKET_VERBOSE_DEBUG_CONTENT
@@ -725,7 +725,7 @@ static void VerboseDebug(const WebSocket::Frame& frame) {
}
}
#endif
fmt::print("WS SendBinary({})\n", str.str());
wpi::print("WS SendBinary({})\n", str.str());
} else {
SmallString<128> str;
#ifdef WPINET_WEBSOCKET_VERBOSE_DEBUG_CONTENT
@@ -736,7 +736,7 @@ static void VerboseDebug(const WebSocket::Frame& frame) {
}
}
#endif
fmt::print("WS SendOp({}, {})\n", frame.opcode, str.str());
wpi::print("WS SendOp({}, {})\n", frame.opcode, str.str());
}
#endif
}

View File

@@ -8,6 +8,7 @@
#include <wpi/StringExtras.h>
#include <wpi/fmt/raw_ostream.h>
#include <wpi/print.h>
#include "wpinet/raw_uv_ostream.h"
#include "wpinet/uv/Buffer.h"
@@ -158,7 +159,7 @@ void WebSocketServer::Abort(uint16_t code, std::string_view reason) {
raw_uv_ostream os{bufs, 1024};
// Handle unsupported version
fmt::print(os, "HTTP/1.1 {} {}\r\n", code, reason);
wpi::print(os, "HTTP/1.1 {} {}\r\n", code, reason);
if (code == 426) {
os << "Upgrade: WebSocket\r\n";
}