| 1423 | ::google::protobuf::Closure* done); |
| 1424 | |
| 1425 | void ProcessHttpRequest(InputMessageBase *msg) { |
| 1426 | const int64_t start_parse_us = butil::cpuwide_time_us(); |
| 1427 | DestroyingPtr<HttpContext> imsg_guard(static_cast<HttpContext*>(msg)); |
| 1428 | SocketUniquePtr socket_guard(imsg_guard->ReleaseSocket()); |
| 1429 | Socket* socket = socket_guard.get(); |
| 1430 | const Server* server = static_cast<const Server*>(msg->arg()); |
| 1431 | ScopedNonServiceError non_service_error(server); |
| 1432 | |
| 1433 | Controller* cntl = new (std::nothrow) Controller; |
| 1434 | if (NULL == cntl) { |
| 1435 | LOG(FATAL) << "Fail to new Controller"; |
| 1436 | return; |
| 1437 | } |
| 1438 | HttpResponseSender resp_sender(cntl); |
| 1439 | resp_sender.set_received_us(msg->received_us()); |
| 1440 | |
| 1441 | const bool is_http2 = imsg_guard->header().is_http2(); |
| 1442 | if (is_http2) { |
| 1443 | H2StreamContext* h2_sctx = static_cast<H2StreamContext*>(msg); |
| 1444 | resp_sender.set_h2_stream_id(h2_sctx->stream_id()); |
| 1445 | } |
| 1446 | |
| 1447 | ControllerPrivateAccessor accessor(cntl); |
| 1448 | HttpHeader& req_header = cntl->http_request(); |
| 1449 | imsg_guard->header().Swap(req_header); |
| 1450 | butil::IOBuf& req_body = imsg_guard->body(); |
| 1451 | butil::EndPoint user_addr; |
| 1452 | if (!GetUserAddressFromHeader(req_header, &user_addr)) { |
| 1453 | user_addr = socket->remote_side(); |
| 1454 | } |
| 1455 | ServerPrivateAccessor server_accessor(server); |
| 1456 | const bool security_mode = server->options().security_mode() && |
| 1457 | socket->user() == server_accessor.acceptor(); |
| 1458 | accessor.set_server(server) |
| 1459 | .set_security_mode(security_mode) |
| 1460 | .set_peer_id(socket->id()) |
| 1461 | .set_remote_side(user_addr) |
| 1462 | .set_local_side(socket->local_side()) |
| 1463 | .set_auth_context(socket->auth_context()) |
| 1464 | .set_request_protocol(is_http2 ? PROTOCOL_H2 : PROTOCOL_HTTP) |
| 1465 | .set_begin_time_us(msg->received_us()) |
| 1466 | .move_in_server_receiving_sock(socket_guard); |
| 1467 | |
| 1468 | // Read log-id. errno may be set when input to strtoull overflows. |
| 1469 | // atoi/atol/atoll don't support 64-bit integer and can't be used. |
| 1470 | const std::string* log_id_str = req_header.GetHeader(common->LOG_ID); |
| 1471 | if (log_id_str) { |
| 1472 | char* logid_end = NULL; |
| 1473 | errno = 0; |
| 1474 | uint64_t logid = strtoull(log_id_str->c_str(), &logid_end, 10); |
| 1475 | if (*logid_end || errno) { |
| 1476 | LOG(ERROR) << "Invalid " << common->LOG_ID << '=' |
| 1477 | << *log_id_str << " in http request"; |
| 1478 | } else { |
| 1479 | cntl->set_log_id(logid); |
| 1480 | } |
| 1481 | } |
| 1482 |
nothing calls this directly
no test coverage detected