net-http icon indicating copy to clipboard operation
net-http copied to clipboard

Allow `Net::HTTP.get`, `get_response`, `post`, `post_form`, `put` to receive URI `String`

Open kyanagi opened this issue 4 years ago • 5 comments

We need to pass a URI object to Net::HTTP.get_response (or Net::HTTP.get).

Net::HTTP.get_response(URI('http://www.example.com/index.html'))

With this patch, these methods can receive a URI-string.

Net::HTTP.get_response('http://www.example.com/index.html')

kyanagi avatar May 01 '21 03:05 kyanagi

IMO it's unreasonable and pointless to define a method with a UTF-16 name, see https://github.com/truffleruby/truffleruby/issues/4005#issuecomment-3450942799. I think CRuby should actually prevent defining such a method in a dummy (Encoding::UTF_16) or ASCII-incompatible encoding (Encoding::UTF_16LE/Encoding::UTF_16BE).

eregon avatar Oct 27 '25 12:10 eregon

I think CRuby should actually prevent defining such a method in a dummy (Encoding::UTF_16) or ASCII-incompatible encoding (Encoding::UTF_16LE/Encoding::UTF_16BE).

What would you like to see? A particular exception thrown?

alexanderadam avatar Oct 27 '25 13:10 alexanderadam

All 3 UTF-16 encodings are ASCII-incompatible:

irb(main):001> Encoding::UTF_16.ascii_compatible?
=> false
irb(main):002> Encoding::UTF_16LE.ascii_compatible?
=> false
irb(main):003> Encoding::UTF_16BE.ascii_compatible?
=> false

And Ruby only supports sources in ASCII-compatible encodings:

$ ruby -e '# encoding: utf-16le'
-e:1: UTF-16LE is not ASCII compatible (ArgumentError)

So I think either an ArgumentError or maybe Encoding::CompatibilityError when define_method receives a name in an ASCII-incompatible encoding. For example filesystem operations reject such ASCII-incompatible encodings:

irb(main):004> File.read("abc".encode(Encoding::UTF_16LE))
(irb):4:in `read': path name must be ASCII-compatible (UTF-16LE): "abc" (Encoding::CompatibilityError)
	from (irb):4:in `<main>'
	from <internal:kernel>:187:in `loop'
	from /home/eregon/.rubies/ruby-3.3.5/lib/ruby/gems/3.3.0/gems/irb-1.13.1/exe/irb:9:in `<top (required)>'
	from /home/eregon/.rubies/ruby-3.3.5/bin/irb:25:in `load'
	from /home/eregon/.rubies/ruby-3.3.5/bin/irb:25:in `<main>'

eregon avatar Oct 28 '25 08:10 eregon