Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError (undefined method `bytesize' for Rack::Utils:Module): #423

Open
diogolmenezes opened this issue Jul 13, 2016 · 2 comments
Open

Comments

@diogolmenezes
Copy link

Hello, i am usng nginx + unicorn in production env, but when my stand alone server receives a request i get this erro at log/websocket_rails_server.log

NoMethodError (undefined method `bytesize' for Rack::Utils:Module):
vendor/bundle/ruby/2.3.0/gems/websocket-rails-0.7.0/lib/websocket_rails/connection_adapters/http.rb:62:in `encode_chunk'

And in line 62 of http.rb ([https://github.com/websocket-rails/websocket-rails/blob/master/lib/websocket_rails/connection_adapters/http.rb]) we have this code block:

 # From [Rack::Stream](https://github.com/intridea/rack-stream)
      def encode_chunk(c)
        return nil if c.nil?
        # hack to work with Rack::File for now, should not TE chunked
        # things that aren't strings or respond to bytesize
        c = ::File.read(c.path) if c.kind_of?(Rack::File)
        size = Rack::Utils.bytesize(c)
        return nil if size == 0
        c.dup.force_encoding(Encoding::BINARY) if c.respond_to?(:force_encoding)
        [size.to_s(16), TERM, c, TERM].join
      end

I searched at Rack::Utils lib for and the method bytesize does not exists, so a open my vendor/bundle/ruby/2.3.0/gems/websocket-rails-0.7.0/lib/websocket_rails/connection_adapters/http.rb file end changed this:

size = Rack::Utils.bytesize(c)

to this:

size = c.bytesize

and it worked. I supose its a websocket-rails bug, could u help ?

@j4zzcat
Copy link

j4zzcat commented Feb 5, 2017

I'm seeing something similar.
NoMethodError: undefined method 'bytesize' for <Array:0x0000000222a400> /usr/local/bundle/gems/rack-1.6.5/lib/rack/utils.rb:380:in 'bytesize' /usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:154:in 'block in finish' /usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:154:in 'each' /usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:154:in 'inject' /usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:154:in 'finish' /usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:918:in 'call!' /usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:895:in 'call' /usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in 'call' /usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in 'call' /usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in 'call' /usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in 'call' /usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in 'call' /usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in 'call' /usr/local/bundle/gems/rack-1.6.5/lib/rack/nulllogger.rb:9:in 'call' /usr/local/bundle/gems/rack-1.6.5/lib/rack/head.rb:13:in 'call' /usr/local/bundle/gems/rack-1.6.5/lib/rack/methodoverride.rb:22:in 'call' /usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:182:in 'call' /usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:2013:in 'call' /usr/local/bundle/gems/rack-test-0.6.3/lib/rack/mock_session.rb:30:in 'request' /usr/local/bundle/gems/rack-test-0.6.3/lib/rack/test.rb:244:in 'process_request' /usr/local/bundle/gems/rack-test-0.6.3/lib/rack/test.rb:58:in 'get' ./spec/token_app_spec.rb:30:in 'block (3 levels) in <top (required)>'

@nesia-amit
Copy link

I got the same:
NoMethodError: undefined method bytesize' for Rack::Utils:Module vendor/bundle/ruby/2.4.0/gems/websocket-rails-0.7.0/lib/websocket_rails/connection_adapters/http.rb:62:in encode_chunk'

I worked around it by adding rack_utils_patch.rb to config/initializers/ with the following content:

module Rack
module Utils
# Return the bytesize of String; uses String#size under Ruby 1.8 and
# String#bytesize under 1.9.
if ''.respond_to?(:bytesize)
def bytesize(string)
string.bytesize
end
else
def bytesize(string)
string.size
end
end
module_function :bytesize

end

end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants