Skip to content

Instantly share code, notes, and snippets.

@shurizzle
Created March 30, 2011 01:23
Show Gist options
  • Save shurizzle/893694 to your computer and use it in GitHub Desktop.
Save shurizzle/893694 to your computer and use it in GitHub Desktop.
FastCGI dispatcher for Padrino in ruby 1.9.x (needed for lighty)
#!/usr/bin/env ruby
# require rack fastcgi {{{
require 'rack/handler/fastcgi'
# support for ruby 1.9.x {{{
class FCGI; class ValuesRecord
def self::read_length(buf)
if buf.getbyte(0) >> 7 == 0
buf.slice!(0, 1).getbyte(0)
else
buf.slice!(0, 4).unpack('N')[0] & ((1 << 31) - 1)
end
end
end; end
# }}}
# }}}
# Magic things {{{
module Kernel
def suppress_warnings
tmp, $VERBOSE = $VERBOSE, nil
result = yield
$VERBOSE = tmp
return result
end
end
# }}}
Kernel.suppress_warnings { # because rack redefine some constants
require ::File.dirname(__FILE__) + '/config/boot.rb'
}
# Correcting dumbness {{{
module Padrino; class Router
alias __real_call__ call
def call(env)
self.__real_call__(env.merge!(
'SCRIPT_NAME' => "",
'PATH_INFO' => File.join(env['SCRIPT_NAME'], env['PATH_INFO'].to_s)
))
end
end; end
# }}}
Rack::Handler::FastCGI.run(Padrino.application)
@shurizzle
Copy link
Author

I'm pleased, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment