Skip to content

Commit

Permalink
fix: ensure headers are set on first commit (#1036)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Nov 7, 2024
1 parent 5c3eba0 commit d622799
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 0 additions & 4 deletions runtime/fastly/builtins/body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#include <optional>
#include <string>

// TODO(GB) remove once https://github.com/bytecodealliance/StarlingMonkey/pull/75 lands
// clang-format off
#include "builtin.h"
// clang-format on
#include "../../../StarlingMonkey/builtins/web/fetch/fetch-errors.h"
#include "../../../StarlingMonkey/builtins/web/streams/native-stream-source.h"
#include "../../../StarlingMonkey/builtins/web/url.h"
Expand Down
12 changes: 11 additions & 1 deletion runtime/fastly/host-api/host_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,18 @@ Result<HttpHeaders *> HttpHeaders::FromEntries(vector<tuple<HostString, HostStri
Result<Void>
write_headers(HttpHeaders *headers,
std::vector<std::tuple<host_api::HostString, host_api::HostString>> &list) {
std::vector<std::string_view> seen;
seen.reserve(list.size());
host_api::Result<host_api::Void> res;
for (const auto &[name, value] : list) {
auto res = headers->append(name, value);
if (std::find(seen.begin(), seen.end(), name) == seen.end()) {
// first time seeing a header -> use set in case of existing values on the handle
res = headers->set(name, value);
seen.push_back(name);
} else {
// seen before -> use append
res = headers->append(name, value);
}
if (res.is_err()) {
return res;
}
Expand Down

0 comments on commit d622799

Please sign in to comment.