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
3 changes: 3 additions & 0 deletions trpc/stream/http/http_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ Status HttpWriteStream::WriteHeader() {
if (content_length_ == kChunked) {
response_->SetHeader(http::kHeaderTransferEncoding, http::kTransferEncodingChunked);
}
if (response_->IsHeaderOnly()) {
content_length_ = 0;
}
response_->SerializeHeaderToString(builder);
return ContextStatusToStreamStatus(context_->SendResponse(builder.DestructiveGet()), [&] {
state_ |= kHeaderWritten;
Expand Down
4 changes: 4 additions & 0 deletions trpc/util/string/string_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ inline std::optional<T> TryParse(const std::string_view& s, const Args&... args)
/// @sa: `std::format`
template <class... Args>
std::string Format(const std::string_view& fmt, const Args&... args) {
#if FMT_VERSION >= 80000
return fmt::format(fmt::runtime(fmt), args...);
#else
return fmt::format(fmt, args...);
#endif
}

/// @brief `std::string(_view)::starts_with/ends_with` is not available until C++20, so
Expand Down
5 changes: 5 additions & 0 deletions trpc/util/string/string_helper_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,9 @@ TEST(String, ToLower) {
ASSERT_EQ("abcd", ToLower("aBCd"));
}

TEST(String, FormatTest) {
std::string fmt_str = "this {} a {} project";
ASSERT_EQ(Format(fmt_str, "is", "trpc-cpp"), "this is a trpc-cpp project");
}

} // namespace trpc::testing
Loading