[Swiftiply-users] swiftiply 0.6.1.1 bug?

Dusty Doris swiftiply at dusty.name
Thu Jan 24 10:09:41 EST 2008


I have just installed swiftiply 0.6.1.1 and I'm testing it out against
a custom mongrel handler.  When I send a request to the swiftiply
instance that does not contain a valid handler, the swiftiplied
mongrel exits instead of returning a 404.

$ cat swiftiply.yml
cluster_address: 0.0.0.0
cluster_port: 2222
daemonize: false
epoll: true
epoll_descriptors: 20000
timeout: 3
map:
  - incoming: localhost
    default: true
    outgoing: 127.0.0.1:30000
    redeployable: true
    redeployable: 114168

$ cat test.rb
require "rubygems"
require "swiftcore/swiftiplied_mongrel"

class HiHandler < Mongrel::HttpHandler
  def process(request,response)
    response.start(200) do |head, out|
      head["Content-Type"] = "text/plain"
      out.write "hi"
    end
  end
end

server = Mongrel::HttpServer.new("127.0.0.1",30000)
server.register("/hi", HiHandler.new)
server.run.join


When I go to:

http://127.0.0.1:2222/hi

It works fine

When I go to:

http://127.0.0.1:2222/bad

I get

$ ruby test.rb
/Library/Ruby/Gems/1.8/gems/swiftiply-0.6.1.1/src/swiftcore/swiftiplied_mongrel.rb:159:in
`process_http_request': undefined method `status=' for nil:NilClass
(NoMethodError)
	from test.rb:15:in `join'
	from test.rb:15


Looking at that line, it appears that the request object is not being
created.  The line in question, has ##### above it.

-------------- snip

    def process_http_request(params,linebuffer,client)
      if not params[Const::REQUEST_PATH]
        uri = URI.parse(params[Const::REQUEST_URI])
        params[Const::REQUEST_PATH] = uri.request_uri
      end

      raise "No REQUEST PATH" if not params[Const::REQUEST_PATH]

      script_name, path_info, handlers =
@classifier.resolve(params[Const::REQUEST_PATH])

      if handlers
        notifiers = handlers.select { |h| h.request_notify }
        request = HttpRequest.new(params, linebuffer, notifiers)

        # request is good so far, continue processing the response
        response = HttpResponse.new(client)

        # Process each handler in registered order until we run out or
one finalizes the response.
        dispatch_to_handlers(handlers,request,response)

        # And finally, if nobody closed the response off, we finalize it.
        unless response.done
          response.finished
        end
      else
        # Didn't find it, return a stock 404 response.
        # This code is changed from the Mongrel behavior because a
content-length
        # header MUST accompany all HTTP responses that go into a swiftiply
        # keepalive connection, so just use the Response object to construct the
        # 404 response.

        #####
        response.status = 404
        response.body = "#{params[Const::REQUEST_PATH]} not found"
        response.finished
      end
    end

-------------------


So, if I add this to the top of that else section before the response
actions are called.

response = HttpResponse.new(client)


Then I get this error instead.

$ ruby test.rb
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.3/lib/mongrel/http_response.rb:102:in
`send_body': undefined method `rewind' for "/bad not found":String
(NoMethodError)
	from test.rb:15:in `join'
	from test.rb:15



Any ideas?


Thanks


Dusty Doris


More information about the Swiftiply-users mailing list