From 59e51bf811a5907983b84f3e2ed14e47a7210e75 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Tue, 26 Mar 2024 13:31:10 +0100 Subject: 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 --- src/zenhttp/httpserver.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/zenhttp/httpserver.cpp') 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(); -- cgit v1.2.3