Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions sig/net-http.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3631,6 +3631,43 @@ module Net
RESPONSE_HAS_BODY: bool
end

# <!-- rdoc-file=lib/net/http/requests.rb -->
# Class for representing [HTTP method
# QUERY](https://www.rfc-editor.org/rfc/rfc10008.html):
#
# require 'net/http'
# uri = URI('http://example.com')
# hostname = uri.hostname # => "example.com"
# uri.path = '/posts'
# req = Net::HTTP::Query.new(uri) # => #<Net::HTTP::Query QUERY>
# req.body = '{"title": "foo","body": "bar","userId": 1}'
# req.content_type = 'application/json'
# res = Net::HTTP.start(hostname) do |http|
# http.request(req)
# end
#
# See [Request Headers](rdoc-ref:Net::HTTPRequest@Request+Headers).
#
# Properties:
#
# * Request body: yes.
# * Response body: yes.
# * [Safe](https://en.wikipedia.org/wiki/HTTP#Safe_method): yes.
# * [Idempotent](https://en.wikipedia.org/wiki/HTTP#Idempotent_method): yes.
# * [Cacheable](https://en.wikipedia.org/wiki/HTTP#Cacheable_method): yes.
#
# Related:
#
# * Net::HTTP#query: sends `QUERY` request, returns response object.
#
class HTTP::Query < HTTPRequest
METHOD: String

REQUEST_HAS_BODY: bool

RESPONSE_HAS_BODY: bool
end

# <!-- rdoc-file=lib/net/http/requests.rb -->
# Class for representing [WebDAV method
# PROPFIND](http://www.webdav.org/specs/rfc4918.html#METHOD_PROPFIND):
Expand Down
21 changes: 21 additions & 0 deletions test_sig/test_net_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,27 @@ def test_http_verbs
end
end

def test_query
with_server("localhost") do |uri|
assert_send_type "(String, String) -> Net::HTTPResponse",
Net::HTTP.start("localhost", uri.port), :query, "/todos", "{\"completed\": false}"
assert_send_type "(String, String, Hash[String, String]) -> Net::HTTPResponse",
Net::HTTP.start("localhost", uri.port), :query, "/todos", "{\"completed\": false}", { "Content-Type" => "application/json" }
assert_send_type "(String, String) { (String) -> untyped } -> Net::HTTPResponse",
Net::HTTP.start("localhost", uri.port), :query, "/todos", "{\"completed\": false}" do |string| string end
assert_send_type "(String, String, Hash[String, String]) { (String) -> untyped } -> Net::HTTPResponse",
Net::HTTP.start("localhost", uri.port), :query, "/todos", "{\"completed\": false}", { "Content-Type" => "application/json" } do |string| string end
assert_send_type "(String, String) -> Net::HTTPResponse",
Net::HTTP.start("localhost", uri.port), :request_query, "/todos", "{\"completed\": false}"
assert_send_type "(String, String, Hash[String, String]) -> Net::HTTPResponse",
Net::HTTP.start("localhost", uri.port), :request_query, "/todos", "{\"completed\": false}", { "Content-Type" => "application/json" }
assert_send_type "(String, String) { (Net::HTTPResponse) -> untyped } -> Net::HTTPResponse",
Net::HTTP.start("localhost", uri.port), :request_query, "/todos", "{\"completed\": false}" do |response| response end
assert_send_type "(String, String, Hash[String, String]) { (Net::HTTPResponse) -> untyped } -> Net::HTTPResponse",
Net::HTTP.start("localhost", uri.port), :request_query, "/todos", "{\"completed\": false}", { "Content-Type" => "application/json" } do |response| response end
end
end

def test_request
with_server("localhost") do |uri|
assert_send_type "(String, String) -> Net::HTTPResponse",
Expand Down