| 346 | } |
| 347 | |
| 348 | static size_t ProcessHttp(const char* buffer, |
| 349 | size_t len, |
| 350 | const HTTPParser::Ptr& httpParser, |
| 351 | const HttpSession::Ptr& httpSession) |
| 352 | { |
| 353 | size_t retlen = len; |
| 354 | if (!httpParser->isCompleted()) |
| 355 | { |
| 356 | retlen = httpParser->tryParse(buffer, len); |
| 357 | if (!httpParser->isCompleted()) |
| 358 | { |
| 359 | return retlen; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | if (httpParser->isWebSocket()) |
| 364 | { |
| 365 | if (httpParser->hasKey("Sec-WebSocket-Key")) |
| 366 | { |
| 367 | auto response = WebSocketFormat::wsHandshake( |
| 368 | httpParser->getValue("Sec-WebSocket-Key")); |
| 369 | httpSession->send(response.c_str(), |
| 370 | response.size()); |
| 371 | } |
| 372 | |
| 373 | const auto& wsConnectedCallback = httpSession->getWSConnectedCallback(); |
| 374 | if (wsConnectedCallback != nullptr) |
| 375 | { |
| 376 | wsConnectedCallback(httpSession, *httpParser); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | return retlen; |
| 381 | } |
| 382 | }; |
| 383 | |
| 384 | }}}// namespace brynet::net::http |
nothing calls this directly
no test coverage detected