Skip to content

Conversation

@Guest0x0
Copy link
Collaborator

This PR refines the @http.run_server helper, replace it with a new type @http.Server:

  • @http.Server can be created via @http.Server::new(..). Separating creation and running of server allows random port for testing etc.
  • @http.Server can be run via .run_forever(..). Compared to @http.run_server, @http.Server::run_forever has the following merits:
    • there is no need to manually loop over requests for each connection. In @http.Server::run_forever, the callback function only need to handle a single request
    • cleaner API: the callback of @http.Server::run_forever accepts three parameters: the request, request body as a &@io.Reaedr, and the server connection for writing response. These parameters have better separation of concern, making request handling code easier to write and less error-prone.
    • forgetting to call .end_response() no longer result in crashing or error, as @http.Server::run_forever can now automatically call .end_response() if the user forgot to do so
  • @http.Server also supports plain .accept(), in case .run_forever(..) is not flexible enough

The old @http.run_server API is deprecated.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 822

Details

  • 7 of 10 (70.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.09%) to 78.649%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/http/server.mbt 7 10 70.0%
Totals Coverage Status
Change from base Build 821: -0.09%
Covered Lines: 1374
Relevant Lines: 1747

💛 - Coveralls

@Guest0x0 Guest0x0 merged commit ee3ebbb into main Nov 21, 2025
11 checks passed
@Guest0x0 Guest0x0 deleted the http-server branch November 21, 2025 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants