net-http
net-http copied to clipboard
Set correct uplevel to warning on supply_default_content_type
This PR fixes uplevel of supply_default_content_type.
Problem
Currently supply_default_content_type specifies an incorrect uplevel to warn method.
For example:
require 'net/http'
url = URI.parse('http://www.example.com/index.html')
req = Net::HTTP::Post.new(url.path)
res = Net::HTTP.start(url.host, url.port) {|http|
http.request(req)
}
res.body
$ ruby test.rb
/Users/kuwabara.masataka/.rbenv/versions/trunk/lib/ruby/3.2.0+0/net/http/generic_request.rb:186: warning: net/http: Content-Type did not set; using application/x-www-form-urlencoded
The warning points to net/http/generic_request.rb which is not written by the user. The location is not helpful to fix the warning by the user.
Solution
Find the correct uplevel from the caller and specify it.
I also considered using a fixed uplevel for it, like uplevel: 6. But I think caller_location is better than the fixed value.
Because the uplevel is too deep, and supply_default_content_type is called from multiple places so the fixed value doesn't work properly for all callers perhaps.
I think a possible direction is to:
- Make
InputMethodact asIOMethod. That is, make it responsible for output too (by addingputsandprintmethods to it?) as Reline/ReadlineInputMethod both already hold@stdoutanyway. - Change all
Kernel#putsinvocation toirb_context.io.puts(with some refactors, ofc).