aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2025-10-02 16:19:40 +0200
committerGitHub Enterprise <[email protected]>2025-10-02 16:19:40 +0200
commit7838d47561dbc2dd42ec3f6b851efb710fec1842 (patch)
treec27673e751c745f95045e794b653d8c9d0d23923 /src
parentadd zenremotestore lib (#540) (diff)
downloadzen-7838d47561dbc2dd42ec3f6b851efb710fec1842.tar.xz
zen-7838d47561dbc2dd42ec3f6b851efb710fec1842.zip
fix for RPC replay issue (wrong content-type) (#536)
likely fall-out from HttpClient refactor. The content type used to be explicit via headers but is now taken from the `IoBuffer` also fixed issue which meant the original request session ID would also not be propagated as intended
Diffstat (limited to 'src')
-rw-r--r--src/zen/cmds/rpcreplay_cmd.cpp30
-rw-r--r--src/zenhttp/httpclient.cpp22
-rw-r--r--src/zenhttp/include/zenhttp/httpclient.h2
-rw-r--r--src/zenserver-test/projectstore-tests.cpp2
4 files changed, 28 insertions, 28 deletions
diff --git a/src/zen/cmds/rpcreplay_cmd.cpp b/src/zen/cmds/rpcreplay_cmd.cpp
index 0cf5e5b6d..d7047d82e 100644
--- a/src/zen/cmds/rpcreplay_cmd.cpp
+++ b/src/zen/cmds/rpcreplay_cmd.cpp
@@ -413,33 +413,11 @@ RpcReplayCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (!m_DryRun)
{
- StringBuilder<32> SessionIdString;
+ Http.SetSessionId(RequestInfo.SessionId);
+ Payload.SetContentType(RequestInfo.ContentType);
- if (RequestInfo.SessionId != Oid::Zero)
- {
- RequestInfo.SessionId.ToString(SessionIdString);
- }
- else
- {
- GetSessionId().ToString(SessionIdString);
- }
-
- HttpClient::KeyValueMap HttpHeaders{
- {"Content-Type", std::string(MapContentTypeToString(RequestInfo.ContentType))},
- {"Accept", std::string(MapContentTypeToString(RequestInfo.AcceptType))},
- {"UE-Session", std::string(SessionIdString)}};
-
- uint64_t Offset = 0;
- auto ReadCallback = [&Payload, &Offset](char* buffer, size_t& size, intptr_t) {
- size = Min<size_t>(size, Payload.GetSize() - Offset);
- IoBuffer PayloadRange = IoBuffer(Payload, Offset, size);
- MutableMemoryView Data(buffer, size);
- Data.CopyFrom(PayloadRange.GetView());
- Offset += size;
- return true;
- };
-
- HttpClient::Response Response = Http.Post("/z$/$rpc", Payload, HttpHeaders);
+ HttpClient::Response Response =
+ Http.Post("/z$/$rpc", Payload, {HttpClient::Accept(RequestInfo.AcceptType)});
BytesSent.fetch_add(Payload.GetSize());
if (!Response)
diff --git a/src/zenhttp/httpclient.cpp b/src/zenhttp/httpclient.cpp
index 3da9f91fc..c5c808c23 100644
--- a/src/zenhttp/httpclient.cpp
+++ b/src/zenhttp/httpclient.cpp
@@ -39,7 +39,14 @@ HttpClientBase::HttpClientBase(std::string_view BaseUri, const HttpClientSetting
, m_BaseUri(BaseUri)
, m_ConnectionSettings(ConnectionSettings)
{
- m_SessionId = GetSessionIdString();
+ if (ConnectionSettings.SessionId == Oid::Zero)
+ {
+ m_SessionId = GetSessionIdString();
+ }
+ else
+ {
+ m_SessionId = ConnectionSettings.SessionId.ToString();
+ }
}
HttpClientBase::~HttpClientBase()
@@ -207,6 +214,19 @@ HttpClient::~HttpClient()
delete m_Inner;
}
+void
+HttpClient::SetSessionId(const Oid& SessionId)
+{
+ if (SessionId == Oid::Zero)
+ {
+ m_SessionId = GetSessionIdString();
+ }
+ else
+ {
+ m_SessionId = SessionId.ToString();
+ }
+}
+
HttpClient::Response
HttpClient::Put(std::string_view Url, const IoBuffer& Payload, const HttpClient::KeyValueMap& AdditionalHeader)
{
diff --git a/src/zenhttp/include/zenhttp/httpclient.h b/src/zenhttp/include/zenhttp/httpclient.h
index aae7b94e5..c1fc1efa6 100644
--- a/src/zenhttp/include/zenhttp/httpclient.h
+++ b/src/zenhttp/include/zenhttp/httpclient.h
@@ -55,6 +55,7 @@ struct HttpClientSettings
bool AssumeHttp2 = false;
bool AllowResume = false;
uint8_t RetryCount = 0;
+ Oid SessionId = Oid::Zero;
};
class HttpClientError : public std::runtime_error
@@ -230,6 +231,7 @@ public:
LoggerRef Log() { return m_Log; }
std::string_view GetBaseUri() const { return m_BaseUri; }
std::string_view GetSessionId() const { return m_SessionId; }
+ void SetSessionId(const Oid& SessionId);
bool Authenticate();
diff --git a/src/zenserver-test/projectstore-tests.cpp b/src/zenserver-test/projectstore-tests.cpp
index ce3e9dcd1..6b70a3c15 100644
--- a/src/zenserver-test/projectstore-tests.cpp
+++ b/src/zenserver-test/projectstore-tests.cpp
@@ -220,7 +220,7 @@ TEST_CASE("project.basic")
{
IoBuffer Payload = MakeCbObjectPayload([&](CbObjectWriter& Writer) { Writer.AddString("method"sv, "snapshot"sv); });
- auto Response = Http.Post("/rpc"sv, Payload, {{"Content-Type", "application/x-ue-cb"}});
+ auto Response = Http.Post("/rpc"sv, Payload);
REQUIRE(Response);
CHECK(Response.StatusCode == HttpResponseCode::OK);
}