Skip to content
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

Update documentation and refactor Rack::Test::Session #295

Merged
merged 6 commits into from May 11, 2022

Conversation

jeremyevans
Copy link
Contributor

See individual commits for changes.

Metaprogram the HTTP verb methods to reduce duplication.

Remove need for @headers instance variable, by having header
method do the name mangling and storing the result in @env.
In addition to being simpler, this is also faster as it
avoids the need to mangling the names in every request.
When mangling names, avoid unnecessary string allocations.
Also remove the @default_host instance variable, since it
was only used in one place.

Avoid array allocation in follow_redirect!.  Also avoid
unnecessary indirection by using custom_request directly.
This will also fix cases where there is a redirect following
a custom_request with an HTTP verb for which there is no
method.

Avoid unnecessary string allocation and method calls in
parse_uri.

Remove default_env and headers_for_env private methods.
Both were only used in one place.  headers_for_env is
no longer needed after the change to header, and
default_env is simple enough to inline. Use a private
frozen constant as the default environment.

Remove inaccurate comments in env_for.  We decided not to
remove support for :method, since it is still supported
in Rack, and Rack::ContentLength has never dealt with
Content-Length in requests, only Content-Length in
responses. Remove unnecessary array allocations in
env_for as well.

Require forwardable, since it is used in this file,
instead of relying on the fact that rack/test/methods
currently requires forwardable.
@jeremyevans jeremyevans requested a review from ioquatix May 11, 2022 21:44
README.md Outdated Show resolved Hide resolved
lib/rack/test.rb Outdated Show resolved Hide resolved
Copy link
Member

@ioquatix ioquatix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, minor feedback.

This is compatible with earlier versions of Rack, and lower-case
headers are required in Rack 3.  Accessing the headers for the
last response uses a case insensitive match.

This also changes the headers used in multipart requests, for
consistency, even though that is not required by the rack SPEC.

While here, remove some bogus comments in the specs about
Rack::ContentLength setting content length for requests.
@jeremyevans jeremyevans merged commit ff190dd into rack:main May 11, 2022
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.

None yet

2 participants