Project

General

Profile

Bug #11281

Unexpected behaviour in HTTP header processing

Added by jcarter@intellicentrics.com (John Carter) about 4 years ago. Updated about 4 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
[ruby-core:69652]

Description

Running this:

Net::HTTP::Get.new('http://any.url', {'header' => nil})

Results in:

NoMethodError: undefined method `strip' for nil:NilClass
    from /home/vagrant/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/http/header.rb:17:in `block in initialize_http_header'
    from /home/vagrant/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/http/header.rb:15:in `each'
    from /home/vagrant/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/http/header.rb:15:in `initialize_http_header'
    from /home/vagrant/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/http/generic_request.rb:43:in `initialize'
    from /home/vagrant/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/http/request.rb:14:in `initialize'
    from (irb):13:in `new'
    from (irb):13

Suggest implementation changes to assume a nil header value is the same as an empty string.

Thanks,

John

History

Updated by nobu (Nobuyoshi Nakada) about 4 years ago

  • Description updated (diff)
  • Status changed from Open to Feedback

Why do you need to give a nil?

Updated by shishir127 (Shishir Joshi) about 4 years ago

I think if the user wants to send a blank header, then the user should do that explicitly like

Net::HTTP::Get.new('http://any.url', {'header' => ""})

Converting a nil value to a blank string is not so obvious behaviour as there is an implicit conversion involved. So I am OK with skipping nil values.

Updated by nobu (Nobuyoshi Nakada) about 4 years ago

  • Status changed from Feedback to Rejected

Shishir Joshi wrote:

So I am OK with skipping nil values.

Then no needs to allow nil?

Updated by shishir127 (Shishir Joshi) about 4 years ago

Nobuyoshi Nakada wrote:

Shishir Joshi wrote:

So I am OK with skipping nil values.

Then no needs to allow nil?

Yes. Nil header doesn't make sense and should be skipped. But I'm not really convinced that this is a good case to raise an exception. Your thoughts?

Also available in: Atom PDF