stormbrew / rack-jetty

Very simple (mostly Ruby) implementation of jetty as a pure Rack adapter.
MIT License
14 stars 6 forks source link

Error with multipart POSTs #4

Open tomdz opened 12 years ago

tomdz commented 12 years ago

I get this error when doing multipart posts against a sinatra app running with rack-jetty:

2011-09-25 17:51:05.932::INFO:  Logging to STDERR via org.mortbay.log.StdErrLog
2011-09-25 17:51:05.973::INFO:  jetty-6.1.14
2011-09-25 17:51:06.01::INFO:  Started SocketConnector@localhost:4567
2011-09-25 17:51:22.015::WARN:  EXCEPTION 
org.jruby.exceptions.RaiseException: (EOFError) bad content body
    at Rack::Multipart::Parser.get_current_head_and_filename_and_content_type_and_name_and_body(/Users/tomdz/.rvm/gems/jruby-1.6.4/gems/rack-1.3.3/lib/rack/multipart/parser.rb:108)
    at Rack::Multipart::Parser.parse(/Users/tomdz/.rvm/gems/jruby-1.6.4/gems/rack-1.3.3/lib/rack/multipart/parser.rb:18)
    at org.jruby.RubyKernel.loop(org/jruby/RubyKernel.java:1419)
    at Rack::Multipart::Parser.parse(/Users/tomdz/.rvm/gems/jruby-1.6.4/gems/rack-1.3.3/lib/rack/multipart/parser.rb:17)
    at #<Class:0x13bf0d7f5>.parse_multipart(/Users/tomdz/.rvm/gems/jruby-1.6.4/gems/rack-1.3.3/lib/rack/multipart.rb:25)
    at Rack::Request.parse_multipart(/Users/tomdz/.rvm/gems/jruby-1.6.4/gems/rack-1.3.3/lib/rack/request.rb:306)
    at Rack::Request.POST(/Users/tomdz/.rvm/gems/jruby-1.6.4/gems/rack-1.3.3/lib/rack/request.rb:182)
    at Rack::MethodOverride.call(/Users/tomdz/.rvm/gems/jruby-1.6.4/gems/rack-1.3.3/lib/rack/methodoverride.rb:15)
    at #<Class:0x1390b755d>.call(/Users/tomdz/.rvm/gems/jruby-1.6.4/gems/sinatra-1.2.6/lib/sinatra/base.rb:1272)
    at #<Class:0x104f9d4f7>.synchronize(/Users/tomdz/.rvm/gems/jruby-1.6.4/gems/sinatra-1.2.6/lib/sinatra/base.rb:1303)
    at #<Class:0x104f9d4f7>.call(/Users/tomdz/.rvm/gems/jruby-1.6.4/gems/sinatra-1.2.6/lib/sinatra/base.rb:1272)
    at RackJetty::ServletHandler.handle(/Users/tomdz/.rvm/gems/jruby-1.6.4/gems/rack-jetty-0.2.0/lib/rack_jetty/servlet_handler.rb:55)

This is against this simple test app:

require 'rubygems'
require 'bundler/setup'
require 'sinatra'
require 'digest/sha1'
require 'fileutils'
require 'rack/handler/jetty'

post '/' do
  "Hello World"
end

set :environment, :production
set :run, false
server = Rack::Handler::Jetty.new(Sinatra::Application, {
  :Host => 'localhost',
  :Port => 4567
})
server.run

using this ruby script to perform the POST:

#!/usr/bin/env ruby
require 'rubygems'
require 'net/http/post/multipart'

url = URI.parse("http://localhost:4567/")
res = Net::HTTP.start(url.host, url.port) do |http|
  req = Net::HTTP::Post::Multipart.new url.path,
        "file" => UploadIO.new("spec/images/image.jpg", "image/jpg")
  http.request(req)
end

(This uses the multipart-post gem).

tomdz commented 12 years ago

FWIW, this works fine wih WEBbrick:


== Sinatra/1.2.6 has taken the stage on 4567 for production with backup from WEBrick
[2011-09-25 17:53:56] INFO  WEBrick 1.3.1
[2011-09-25 17:53:56] INFO  ruby 1.8.7 (2011-08-23) [java]
[2011-09-25 17:53:56] INFO  WEBrick::HTTPServer#start: pid=71855 port=4567
127.0.0.1 - - [25/Sep/2011 17:54:07] "POST / HTTP/1.1" 200 11 0.0250
localhost - - [25/Sep/2011:17:54:07 PDT] "POST / HTTP/1.1" 200 11
- -> /
stormbrew commented 12 years ago

Interesting, thanks. I'll take a look at it as soon as I can. At first glance, it's definitely doing something strange -- the input stream the server is seeing seems to have the data duplicated many times, but this shouldn't be so. Not sure why. Might be a problem in Rack::Rewindable, but I'll definitely have a look at if it's a problem in rack-jetty itself. The code around this isn't very complex on this front, though.

regularfry commented 11 years ago

Duplicated data in the POST body is exactly the problem https://github.com/stormbrew/rack-jetty/pull/6 fixes - I suspect these are the same issue.