Tag: RVM

Ruby on Rails + Webrick: ERROR NoMethodError: undefined method ‘split’ for nil:NilClass

Recently after updating Ruby on Rails, after runnig Webrick in a development mode, it started to crush with such an error:

 ERROR NoMethodError: undefined method `split' for nil:NilClass
    /home/path/gems/rack-1.4.3/lib/rack/handler/webrick.rb:68:in `block in service'
    /home/path/gems/rack-1.4.3/lib/rack/utils.rb:387:in `block in each'
    /home/path/gems/rack-1.4.3/lib/rack/utils.rb:386:in `each'
    /home/path/gems/rack-1.4.3/lib/rack/utils.rb:386:in `each'
    /home/path/gems/rack-1.4.3/lib/rack/handler/webrick.rb:62:in `service'
    /home/path/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
    /home/path/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
    /home/path/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

I don't know why it happens but I know how to fix it ;)
To do so, you need to find 68 line in a Webric server:

# Ofc change the path to your Webrick path
vim /home/path/gems/rack-1.4.3/lib/rack/handler/webrick.rb

Localize line 68 and change:

res[k] = vs.split("\n").join(", ")

to:

res[k] = vs.to_s.split("\n").join(", ")

It seams that the header value is somehow nil, that's why we cast it to empty string.

Ruby 1.9.3 + OpenSSL::SSL::SSLError issue

Problem

OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3
read server certificate B: certificate verify failed
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799:in
`connect'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799:in
`block in connect'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:68:in
`timeout'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:99:in
`timeout'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799:in
`connect'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:755:in
`do_start'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:750:in
`start'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/xmlrpc/client.rb:535:in
`do_rpc'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/xmlrpc/client.rb:420:in
`call2'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/xmlrpc/client.rb:410:in
`call'
from /path/infusionsoft/connection.rb:15:in
`connection'
from /path/infusionsoft/request.rb:29:in
`request'
from /path/infusionsoft/request.rb:5:in
`get'
from /path/infusionsoft/client/contact.rb:59:in
`contact_find_by_email'
from /path/infusionsoft.rb:18:in
`method_missing'
from (irb):2
from /path/rails/commands/console.rb:45:in
`start'
from /path/rails/commands/console.rb:8:in
`start'
from /path/rails/commands.rb:40:in
`<top (required)>'
from ./script/rails:6:in `require'
from ./script/rails:6:in

Solution

To work this around, we need to overwrite use_ssl method:

module Net
  class HTTP
    def use_ssl=(flag)
      flag = flag ? true : false
      if started? and @use_ssl != flag
        raise IOError, "use_ssl value changed, but session already started"
      end
      @use_ssl = flag
      if @use_ssl
        self.verify_mode = OpenSSL::SSL::VERIFY_NONE
      end
    end
  end
end

Copyright © 2024 Closer to Code

Theme by Anders NorenUp ↑