MCPcopy Create free account
hub / github.com/FISCO-BCOS/FISCO-BCOS / buildHttpResp

Method buildHttpResp

bcos-boostssl/bcos-boostssl/httpserver/HttpSession.cpp:182–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

180 }
181}
182bcos::boostssl::http::HttpResponsePtr bcos::boostssl::http::HttpSession::buildHttpResp(
183 boost::beast::http::status status, bool keepAlive, unsigned version, bcos::bytes content,
184 const CorsConfig& corsConfig) const
185{
186 auto msg = std::make_shared<HttpResponse>(status, version);
187 msg->set(boost::beast::http::field::server, BOOST_BEAST_VERSION_STRING);
188 msg->set(boost::beast::http::field::content_type, "application/json");
189 msg->keep_alive(keepAlive); // default , keep alive
190 msg->body() = std::move(content);
191
192 // set cors config
193 if (corsConfig.enableCORS)
194 {
195 msg->set(boost::beast::http::field::access_control_allow_origin, corsConfig.allowedOrigins);
196 msg->set(
197 boost::beast::http::field::access_control_allow_methods, corsConfig.allowedMethods);
198 msg->set(
199 boost::beast::http::field::access_control_allow_headers, corsConfig.allowedHeaders);
200 msg->set(
201 boost::beast::http::field::access_control_max_age, std::to_string(corsConfig.maxAge));
202 msg->set(boost::beast::http::field::access_control_allow_credentials,
203 corsConfig.allowCredentials ? "true" : "false");
204 }
205
206 // TODO: limit response body size
207
208 msg->prepare_payload();
209 return msg;
210}
211bcos::boostssl::http::HttpReqHandler bcos::boostssl::http::HttpSession::httpReqHandler() const
212{
213 return m_httpReqHandler;

Callers 2

handleRequestMethod · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80

Calls 1

setMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.64