http_response.hpp (291d709d3505cb345259e7d78eb6c8b765499c1b) | http_response.hpp (2d6cb56b6b47c3fbb0d234ade5c1208edb69ef1f) |
---|---|
1#pragma once 2#include "logging.hpp" 3#include "nlohmann/json.hpp" 4 5#include <boost/beast/http/message.hpp> 6#include <boost/beast/http/string_body.hpp> 7#include <utils/hex_utils.hpp> 8 --- 147 unchanged lines hidden (view full) --- 156 expectedHash = std::nullopt; 157 } 158 159 void write(std::string_view bodyPart) 160 { 161 stringResponse->body() += std::string(bodyPart); 162 } 163 | 1#pragma once 2#include "logging.hpp" 3#include "nlohmann/json.hpp" 4 5#include <boost/beast/http/message.hpp> 6#include <boost/beast/http/string_body.hpp> 7#include <utils/hex_utils.hpp> 8 --- 147 unchanged lines hidden (view full) --- 156 expectedHash = std::nullopt; 157 } 158 159 void write(std::string_view bodyPart) 160 { 161 stringResponse->body() += std::string(bodyPart); 162 } 163 |
164 void end() | 164 std::string computeEtag() const |
165 { 166 // Only set etag if this request succeeded | 165 { 166 // Only set etag if this request succeeded |
167 if (result() == boost::beast::http::status::ok) | 167 if (result() != boost::beast::http::status::ok) |
168 { | 168 { |
169 // and the json response isn't empty 170 if (!jsonValue.empty()) 171 { 172 size_t hashval = std::hash<nlohmann::json>{}(jsonValue); 173 std::string hexVal = "\"" + intToHexString(hashval, 8) + "\""; 174 addHeader(boost::beast::http::field::etag, hexVal); 175 } | 169 return ""; |
176 } | 170 } |
171 // and the json response isn't empty 172 if (jsonValue.empty()) 173 { 174 return ""; 175 } 176 size_t hashval = std::hash<nlohmann::json>{}(jsonValue); 177 return "\"" + intToHexString(hashval, 8) + "\""; 178 } 179 180 void end() 181 { 182 std::string etag = computeEtag(); 183 if (!etag.empty()) 184 { 185 addHeader(boost::beast::http::field::etag, etag); 186 } |
|
177 if (completed) 178 { 179 BMCWEB_LOG_ERROR << this << " Response was ended twice"; 180 return; 181 } 182 completed = true; 183 BMCWEB_LOG_DEBUG << this << " calling completion handler"; 184 if (completeRequestHandler) --- 72 unchanged lines hidden --- | 187 if (completed) 188 { 189 BMCWEB_LOG_ERROR << this << " Response was ended twice"; 190 return; 191 } 192 completed = true; 193 BMCWEB_LOG_DEBUG << this << " calling completion handler"; 194 if (completeRequestHandler) --- 72 unchanged lines hidden --- |