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

Upgrade data is not parsed correctly on JRuby #23

Open
jcoglan opened this issue Mar 19, 2013 · 4 comments
Open

Upgrade data is not parsed correctly on JRuby #23

jcoglan opened this issue Mar 19, 2013 · 4 comments

Comments

@jcoglan
Copy link

jcoglan commented Mar 19, 2013

I discovered this while investigating faye/faye-websocket-ruby#18.

The following script constructs a draft-76 WebSocket request with 8 random bytes of upgrade data in the body after the headers. It then uses Http::Parser to process it and spit out the expected and parsed upgrade data bytes:

require 'http/parser'

upgrade_data = (1..8).map { rand 255 }

bytes = [ 71, 69, 84, 32, 47, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 85,
          112, 103, 114, 97, 100, 101, 58, 32, 87, 101, 98, 83, 111, 99, 107,
          101, 116, 13, 10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58,
          32, 85, 112, 103, 114, 97, 100, 101, 13, 10, 72, 111, 115, 116, 58,
          32, 108, 111, 99, 97, 108, 104, 111, 115, 116, 58, 55, 48, 48, 49,
          13, 10, 79, 114, 105, 103, 105, 110, 58, 32, 104, 116, 116, 112, 58,
          47, 47, 108, 111, 99, 97, 108, 104, 111, 115, 116, 58, 55, 48, 48,
          49, 13, 10, 83, 101, 99, 45, 87, 101, 98, 83, 111, 99, 107, 101, 116,
          45, 75, 101, 121, 49, 58, 32, 49, 57, 32, 111, 49, 55, 32, 54, 50,
          32, 52, 32, 53, 50, 13, 10, 83, 101, 99, 45, 87, 101, 98, 83, 111,
          99, 107, 101, 116, 45, 75, 101, 121, 50, 58, 32, 79, 52, 32, 48, 97,
          103, 39, 53, 121, 57, 32, 32, 72, 32, 54, 60, 32, 54, 101, 32, 57,
          49, 50, 13, 10, 13, 10] +

        upgrade_data

string = bytes.pack('C*')
parser = Http::Parser.new

parser << string
puts 'Expected bytes:'
p upgrade_data
puts 'Actual bytes:'
p parser.upgrade_data.bytes.to_a

On MRI 1.9.3-p392, the expected and actual results always match. But on JRuby 1.7.2, the actual output bytes are different from the expected ones, and parser.upgrade_data often contains more than the intended 8 bytes.

I'm not sure if I'm using it wrong or if this is a bug in Http::Parser.

@tmm1
Copy link
Owner

tmm1 commented Mar 19, 2013

This might be fixed on the latest-upstream branch.

@samflores
Copy link

What are the steps to use latest-upstream branch?

I've tried adding gem 'http_parser.rb', git: 'https://github.com/tmm1/http_parser.rb.git', branch: 'latest-upstream' to Gemfile and cloning the source and build the gem myself, but in both cases I get:

ERROR:  Error installing pkg/http_parser.rb-0.5.3.gem:
        ERROR: Failed to build gem native extension.

        /opt/rubies/jruby-1.7.3/bin/jruby extconf.rb
NotImplementedError: C extension support is not enabled. Pass -Xcext.enabled=true to JRuby or set JRUBY_OPTS or modify .jrubyrc to enable.

   (root) at /opt/rubies/jruby-1.7.3/lib/ruby/shared/mkmf.rb:8
  require at org/jruby/RubyKernel.java:1027
   (root) at /opt/rubies/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:1
   (root) at extconf.rb:1

@jcoglan
Copy link
Author

jcoglan commented Mar 25, 2013

@samflores you might also have a bad time due to Goliath locking its http_parser dep to = 0.5.3.

@samflores
Copy link

@jcoglan Rubygems dependency management is not my area of expertise, but It seems the version in http_parser.rb.gemspec of the latest-upstream branch is still set to 0.5.3, so I guess if I can point my Gemfile to git: 'https://github.com/tmm1/http_parser.rb.git', branch: 'latest-upstream' and actually build it I'd be fine (unless I've understood it wrong).

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