Project

General

Profile

Actions

Feature #14615

open

Consider introducing shortcut to check Net::HTTP response type

Added by artur86 (Artur *) over 3 years ago. Updated over 3 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:86192]

Description

Currently you need to either use kind_of? or HTTPResponse#code to find out the type of a response.

response = Net::HTTP.start(uri.hostname, 
                           uri.port,
                           use_ssl: (uri.scheme == 'https'),
                           cert: OpenSSL::X509::Certificate.new(client_cert),
                           key: OpenSSL::PKey::RSA.new(client_key)) do |http|
  http.request(request)
end

if response.code || response.kind_of?(Net::HTTPSuccess)
  ...
end

How about using data from either Rack::Utils::SYMBOL_TO_STATUS_CODE or Net::HTTPResponse::CODE_TO_OBJ to simply it to:

if response.ok?
...
end

in the same way as Rails does https://github.com/rails/rails/blob/2090615d39c071c9eb25e715275eb79f3f9b6266/actionpack/lib/action_dispatch/testing/assertions/response.rb#L18?

Actions

Also available in: Atom PDF