Cleanup (http-server): refactor and tidy HTTP server implementation#2284
Cleanup (http-server): refactor and tidy HTTP server implementation#2284stephenberry merged 9 commits intostephenberry:mainfrom
Conversation
This removes the need to pass method, target, headers, body, and similar request data through function arguments or lambda captures.
|
Nice cleanup on the request handling! I took a look at the implementation and noticed a critical issue with the request_ state persistence. |
…th_conn()` We now use `send_error_response_with_close()` in case the websocket handler is not found.
|
Thanks — you're absolutely right. I've added clear() calls to reset the request structure before processing the next request when using "Connection: keep-alive". |
|
It looks solid! Resetting the request state was crucial for keeping things alive, and the new error handling for WS/streaming is much more reliable. One minor note: the old send_response methods (for raw sockets) seem to be unused now and can be removed. |
|
Thanks @clagix for this contribution, and @wilkolbrzym-coder for looking over this PR. I'll try to look over this soon to get it merged. |
You're welcome! Glad I could help. |
|
Thanks, @stephenberry, for considering the PR, and thanks, @wilkolbrzym-coder, for the review and helpful suggestions! |
This method is now replaced by `send_response_with_conn()`
|
I’ve also removed the unused send_response() method. I’d prefer to move all What do you think about this approach, @stephenberry and @wilkolbrzym-coder ? |
While the OOP approach is cleaner, process_full_request needs access to the router owned by the server. Moving it to connection_state introduces coupling complications (server dependencies). |
|
@wilkolbrzym-coder you’re right. We should wrap up this PR and prepare it for merge. The primary goal of this PR is to improve code readability, with some minor improvements to security and performance. We can then prepare a follow-up PR to move the _with_conn methods and evaluate any new dependencies or couplings introduced by those changes. |
|
I reviewed the changes and I think this cleanup is in a good place. More cleanup and optimization can happen in future requests. So, I'll merge it in. Thanks for the contributions, it's always nice to simplify code! |
|
We could probably pass conn->request_ directly to start() here. I left the // Create request object for WebSocket handler (move since conn is consumed)
request req{std::move(conn->request_)}; |
process_full_request(which seems to be replaced by the almost identically methodprocess_full_request_with_conn)