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
18 changes: 18 additions & 0 deletions lib/net/http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,22 @@ def initialize(path, initheader = nil)
self.class::RESPONSE_HAS_BODY,
path, initheader
end

# Returns whether the request may have a body:
#
# Net::HTTP::Post.request_body_permitted? # => true
# Net::HTTP::Get.request_body_permitted? # => false
#
def self.request_body_permitted?
self::REQUEST_HAS_BODY
end

# Returns whether the response may have a body:
#
# Net::HTTP::Post.response_body_permitted? # => true
# Net::HTTP::Head.response_body_permitted? # => false
#
def self.response_body_permitted?
self::RESPONSE_HAS_BODY
end
end
22 changes: 22 additions & 0 deletions sig/net-http.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3312,6 +3312,28 @@ module Net
#
def initialize: (String path, ?headers initheader) -> void
| (URI::Generic uri, ?headers initheader) -> void

# <!--
# rdoc-file=lib/net/http/request.rb
# - request_body_permitted?()
# -->
# Returns whether the request may have a body:
#
# Net::HTTP::Post.request_body_permitted? # => true
# Net::HTTP::Get.request_body_permitted? # => false
#
def self.request_body_permitted?: () -> bool

# <!--
# rdoc-file=lib/net/http/request.rb
# - response_body_permitted?()
# -->
# Returns whether the response may have a body:
#
# Net::HTTP::Post.response_body_permitted? # => true
# Net::HTTP::Head.response_body_permitted? # => false
#
def self.response_body_permitted?: () -> bool
end

# <!-- rdoc-file=lib/net/http/requests.rb -->
Expand Down
10 changes: 10 additions & 0 deletions test/net/http/test_http_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,14 @@ def test_update_uri
assert_equal "[2001:db8::1]", req.uri.host
assert_equal 8080, req.uri.port
end

def test_request_body_permitted?
assert_predicate Net::HTTP::Post, :request_body_permitted?
assert_not_predicate Net::HTTP::Get, :request_body_permitted?
end

def test_response_body_permitted?
assert_predicate Net::HTTP::Post, :response_body_permitted?
assert_not_predicate Net::HTTP::Head, :response_body_permitted?
end
end
17 changes: 17 additions & 0 deletions test_sig/test_net_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,23 @@ def test_iteration_on_headers
end
end

class TestSingletonNetHTTPRequest < Test::Unit::TestCase
include RBS::UnitTest::TypeAssertions

library "net-http"
testing "singleton(::Net::HTTPRequest)"

def test_request_body_permitted?
assert_send_type "() -> bool",
Net::HTTP::Post, :request_body_permitted?
end

def test_response_body_permitted?
assert_send_type "() -> bool",
Net::HTTP::Post, :response_body_permitted?
end
end

class TestSingletonNetHTTPResponse < Test::Unit::TestCase
include RBS::UnitTest::TypeAssertions

Expand Down