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

POST request with no length information breaks (JRUBY) #53

Open
HoneyryderChuck opened this issue Oct 11, 2017 · 1 comment
Open

POST request with no length information breaks (JRUBY) #53

HoneyryderChuck opened this issue Oct 11, 2017 · 1 comment

Comments

@HoneyryderChuck
Copy link

No description provided.

@HoneyryderChuck
Copy link
Author

Usually, when a POST request is parsed, one either expects a Content-Length or a Transfer-Encoding: chunked in the headers. When none of these present themselves, the server can respond with "411 Length Required".
The C-based parser parses the request (sometimes it breaks with "not parse data entirely" error) enough for me to identify the error and respond (it also considers the message complete before parsing the incoming body).
The Java parser just breaks with an "invalid method" exception:

HTTP::Parser::Error: invalid method
      << at org/ruby_http_parser/RubyHttpParser.java:372

Below you'll find a script which demonstrates the issue. I don't know if you consider one or the other more valid (I stand for the first one), but they both need to have the same behaviour.

 require "http_parser"
  
  
 $payload = "POST / HTTP/1.1\r\nAccept-Encoding: identity;q=1.0\r\nAccept: */*\r\nUser-Agent: Ruby\r\nHost: 127.0.0.1:58229\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\nonetwothree".b
  
 $parser = HTTP::Parser.new
  
 $parser.on_message_begin = -> { puts "started!!!" }
 $parser.on_headers_complete = -> (h) { puts "headers! #{h}" }
 $parser.on_body = -> (ch) { puts "chunk! #{ch}" }
 $parser.on_message_complete = -> { puts "we're done!!" }
 
 $parser << $payload

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

1 participant