| 180 | } |
| 181 | } |
| 182 | bcos::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 | } |
| 211 | bcos::boostssl::http::HttpReqHandler bcos::boostssl::http::HttpSession::httpReqHandler() const |
| 212 | { |
| 213 | return m_httpReqHandler; |