-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract req/resp methods to new request.rb from server.rb #2419
Conversation
@@ -0,0 +1,438 @@ | |||
# frozen_string_literal: true | |||
|
|||
module Puma |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is going to be a composed object extraction, this file should be Puma::Server::Request
and then live in lib/puma/server/request.rb
.
# frozen_string_literal: true | ||
|
||
module Puma | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you've found a seam but haven't quite cut through all the way yet. I think you can go all the way to a composed object:
while true
case Request.new(client,buffer).handle
... and then in lib/puma/server/request.rb
, everything except handle_request
can be marked private.
This would greatly reduce the API surface of Server. Right now this moves methods around in different files, but with a composed object we could really make Server a lot smaller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did think about this. Two items:
-
It would be a breaking API change.
handle_request
andnormalize_env
are currently public methods of Server. -
Coupling - the following Server instance variables are used in Request code:
@app available
@early_hints available
@events available
@queue_requests hidden
@thread_pool hidden
We could add a couple of readers and pass the server instance into the class init? Also, re class init, I'm not sure if the buffer should/can be contained within Request, rather than be passed in.
I thought that the current layout would maintain the API, but make it easy to create a class when v6.0.0 was being considered.
But, re API changes, the earlier issue with the API changes I made affected parts of the API that could be used for Puma startup/setup. These changes are more 'runtime'. Possibly less likely to cause issues...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, got it. I'll re-review this with a mind to "this is a temporary stopping point to an extraction"
Ok, LGTM. We can revisit this for an extracted object when 6.0 rolls around. |
Wrong button, lol |
Description
server.rb is a very long file with several very long methods.
Extract
default_server_port
,fast_write
,fetch_status_code
,handle_request
,normalize_env
,possible_header_injection?
, andstr_early_hints
from server.rb to request.rbExtract
req_env_post_parse
andstr_headers
fromhandle_request
Updated comments/documentation
See https://msp-greg.github.io/puma/Puma/Request.html for the doc of the PR.
Your checklist for this pull request
[changelog skip]
or[ci skip]
to the pull request title.[ci skip]
to the title of the PR.#issue
" to the PR description or my commit messages.