| 445 | } |
| 446 | |
| 447 | void HttpServerConnection::ProcessMessages(boost::asio::yield_context yc) |
| 448 | { |
| 449 | namespace beast = boost::beast; |
| 450 | namespace http = beast::http; |
| 451 | namespace ch = std::chrono; |
| 452 | |
| 453 | try { |
| 454 | /* Do not reset the buffer in the state machine. |
| 455 | * EnsureValidHeaders already reads from the stream into the buffer, |
| 456 | * EnsureValidBody continues. ProcessRequest() actually handles the request |
| 457 | * and needs the full buffer. |
| 458 | */ |
| 459 | beast::flat_buffer buf; |
| 460 | |
| 461 | while (m_WaitGroup->IsLockable()) { |
| 462 | m_Seen = ch::steady_clock::now(); |
| 463 | |
| 464 | HttpApiRequest request(m_Stream); |
| 465 | HttpApiResponse response(m_Stream, this); |
| 466 | |
| 467 | request.Parser().header_limit(1024 * 1024); |
| 468 | request.Parser().body_limit(-1); |
| 469 | |
| 470 | response.set(http::field::server, l_ServerHeader); |
| 471 | if (auto listener (ApiListener::GetInstance()); listener) { |
| 472 | if (Dictionary::Ptr headers = listener->GetHttpResponseHeaders(); headers) { |
| 473 | ObjectLock lock(headers); |
| 474 | for (auto& [header, value] : headers) { |
| 475 | if (value.IsString()) { |
| 476 | response.set(header, value.Get<String>()); |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | if (!EnsureValidHeaders(buf, request, response, m_ShuttingDown, yc)) { |
| 483 | break; |
| 484 | } |
| 485 | |
| 486 | m_Seen = ch::steady_clock::now(); |
| 487 | auto start (ch::steady_clock::now()); |
| 488 | |
| 489 | { |
| 490 | auto method (http::string_to_verb(request["X-Http-Method-Override"])); |
| 491 | |
| 492 | if (method != http::verb::unknown) { |
| 493 | request.method(method); |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | HandleExpect100(m_Stream, request, yc); |
| 498 | |
| 499 | if (m_ApiUser) { |
| 500 | request.User(m_ApiUser); |
| 501 | } else { |
| 502 | request.User(ApiUser::GetByAuthHeader(std::string(request[http::field::authorization]))); |
| 503 | } |
| 504 |
nothing calls this directly
no test coverage detected