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

Error with multipart POSTs #4

Open
tomdz opened this issue Sep 26, 2011 · 3 comments
Open

Error with multipart POSTs #4

tomdz opened this issue Sep 26, 2011 · 3 comments

Comments

@tomdz
Copy link

tomdz commented Sep 26, 2011

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
Copy link
Author

tomdz commented Sep 26, 2011

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
Copy link
Owner

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
Copy link

Duplicated data in the POST body is exactly the problem #6 fixes - I suspect these are the same issue.

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