You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement Connection in terms of Net::HTTP Request
Proposal
---
This commit changes the private `Connection#request` method to invoke
[Net::HTTP#request][], rather than the individual verb methods (like
[get][], [post][], etc.).
Since the `Net::HTTP#request` method expects an instance (rather than
its constituent parts), this commit also changes the
`Connection#request` method to construct an instance of the HTTP
method-appropriate class:
* `GET` builds [Net::HTTP::Get][]
* `PUT` builds [Net::HTTP::Put][]
* `POST` builds [Net::HTTP::Post][]
* `PATCH` builds [Net::HTTP::Patch][]
* `DELETE` builds [Net::HTTP::Delete][]
* `HEAD` builds [Net::HTTP::Head][]
While the behavior changes aim to be minimal, the availability of a
Net::HTTP request instance enables more future pre-request modifications
(for example, to support for Files through `multipart/form-data`
requests like outlined in [#394][]).
Additional information
---
Net::HTTP Request instances downcase all HTTP header names, but supports
reading from values regardless of the key's casing:
```ruby
request["Accept"] = "application/json" # => "application/json"
request.each.to_h # => {"accept"=>"application/json"}
request["Accept"] # => "application/json"
request["accept"] # => "application/json"
```
Additionally, new Net::HTTP Request instances come with default headers:
```
accept-encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
user-agent: Ruby
host: 37s.sunrise.i:3000
```
The `host:` key is inferred from the request instance's URI.
For the sake of backwards compatibility, this commit clears all default
headers prior to merging any provided or inferred headers (like
`content-type` or `accept`).
[Net::HTTP#request]: https://docs.ruby-lang.org/en/master/Net/HTTP.html#method-i-request
[get]: https://docs.ruby-lang.org/en/master/Net/HTTP.html#method-c-get
[post]: https://docs.ruby-lang.org/en/master/Net/HTTP.html#method-c-post
[Net::HTTP::Get]: https://docs.ruby-lang.org/en/master/Net/HTTP/Get.html
[Net::HTTP::Put]: https://docs.ruby-lang.org/en/master/Net/HTTP/Put.html
[Net::HTTP::Post]: https://docs.ruby-lang.org/en/master/Net/HTTP/Post.html
[Net::HTTP::Patch]: https://docs.ruby-lang.org/en/master/Net/HTTP/Patch.html
[Net::HTTP::Delete]: https://docs.ruby-lang.org/en/master/Net/HTTP/Delete.html
[Net::HTTP::Head]: https://docs.ruby-lang.org/en/master/Net/HTTP/Head.html
[#394]: #394
0 commit comments