aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/httpserver.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2024-03-26 13:31:10 +0100
committerGitHub Enterprise <[email protected]>2024-03-26 13:31:10 +0100
commit59e51bf811a5907983b84f3e2ed14e47a7210e75 (patch)
treea8418dec9b8184ad76d6922da23cebe9db290897 /src/zenhttp/httpserver.cpp
parentadd filter to projectstore entries request (#25) (diff)
downloadzen-59e51bf811a5907983b84f3e2ed14e47a7210e75.tar.xz
zen-59e51bf811a5907983b84f3e2ed14e47a7210e75.zip
add yaml serialization support (#3)
this change adds serialization of payloads as YAML, but not parsing. The implementation is somewhat based on the JSON path, and may be collapsed eventually as it is possible to serialize JSON format using the same code it also separates out the JSON serialization into a separate file for ease of maintenance any HTTP request response may be formatted as yaml by using a `.yaml` suffix or an `Accept: text/yaml` header
Diffstat (limited to 'src/zenhttp/httpserver.cpp')
-rw-r--r--src/zenhttp/httpserver.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/zenhttp/httpserver.cpp b/src/zenhttp/httpserver.cpp
index adb3128bf..a0d4ef3f3 100644
--- a/src/zenhttp/httpserver.cpp
+++ b/src/zenhttp/httpserver.cpp
@@ -477,6 +477,11 @@ HttpServerRequest::WriteResponse(HttpResponseCode ResponseCode, CbObject Data)
ExtendableStringBuilder<1024> Sb;
WriteResponse(ResponseCode, HttpContentType::kJSON, Data.ToJson(Sb).ToView());
}
+ else if (m_AcceptType == HttpContentType::kYAML)
+ {
+ ExtendableStringBuilder<1024> Sb;
+ WriteResponse(ResponseCode, HttpContentType::kYAML, Data.ToYaml(Sb).ToView());
+ }
else
{
SharedBuffer Buf = Data.GetBuffer();
@@ -493,6 +498,11 @@ HttpServerRequest::WriteResponse(HttpResponseCode ResponseCode, CbArray Array)
ExtendableStringBuilder<1024> Sb;
WriteResponse(ResponseCode, HttpContentType::kJSON, Array.ToJson(Sb).ToView());
}
+ else if (m_AcceptType == HttpContentType::kYAML)
+ {
+ ExtendableStringBuilder<1024> Sb;
+ WriteResponse(ResponseCode, HttpContentType::kYAML, Array.ToYaml(Sb).ToView());
+ }
else
{
SharedBuffer Buf = Array.GetBuffer();