lib/fishwife/rack_servlet.rb
# Turns a Servlet request into a Rack request hash.
Turns a Servlet request into a Rack request hash.
Turns a Servlet request into a Rack request hash .
def servlet_to_rack(request)
      env = Hash.new
      env['REQUEST_METHOD'] = request.getMethod
      qstring = request.getQueryString.to_s 
      env['QUERY_STRING'] = qstring
      env['SERVER_NAME'] = request.getServerName
      env['SERVER_PORT'] = request.getServerPort.to_s
      env['rack.version'] = Rack::VERSION
      env['rack.url_scheme'] = request.getScheme
      env['HTTP_VERSION'] = request.getProtocol
      env["SERVER_PROTOCOL"] = request.getProtocol
      env['REMOTE_ADDR'] = request.getRemoteAddr
      env['REMOTE_HOST'] = request.getRemoteHost
      env['REQUEST_PATH'] = request.getRequestURI
      env['PATH_INFO'] = request.getRequestURI
      env['SCRIPT_NAME'] = ""
      req_uri = request.getRequestURL.to_s
      req_uri << '?' << qstring unless qstring.empty?
      env['REQUEST_URI'] = req_uri
      ctype = request.getContentType
      env['CONTENT_TYPE'] = ctype if ctype && !ctype.empty?
      clength = request.getContentLength
      env['CONTENT_LENGTH'] = clength.to_s if clength != -1
      env['rack.multiprocess'] = false
      env['rack.multithread'] = true
      env['rack.run_once'] = false
      hn = request.getHeaderNames
      if hn.respond_to?( :each )
        hn.each do |header_name|
          header = header_name.upcase.tr('-', '_')
          next if header == 'CONTENT_TYPE' || header == 'CONTENT_LENGTH'
          env[ 'HTTP_' + header ] = request.getHeader( header_name )
        end
      else
        @log.warn( "Weird headers: [#{ hn.to_s }]" )
      end
      env['rack.input'] = env['fishwife.input'] =
        convert_input( request.input_stream, clength )
      env['rack.errors'] ||= $stderr
      env['rack.hijack?'] = true
      env['rack.hijack'] = REQ_HIJACK_NOT_SUPPORTED
      env
    end
def servlet_to_rack ( request ) env = Hash . new env [ 'REQUEST_METHOD' ] = request . getMethod qstring = request . getQueryString . to_s env [ 'QUERY_STRING' ] = qstring env [ 'SERVER_NAME' ] = request . getServerName env [ 'SERVER_PORT' ] = request . getServerPort . to_s env [ 'rack.version' ] = Rack :: VERSION env [ 'rack.url_scheme' ] = request . getScheme env [ 'HTTP_VERSION' ] = request . getProtocol env [ "SERVER_PROTOCOL" ] = request . getProtocol env [ 'REMOTE_ADDR' ] = request . getRemoteAddr env [ 'REMOTE_HOST' ] = request . getRemoteHost env [ 'REQUEST_PATH' ] = request . getRequestURI env [ 'PATH_INFO' ] = request . getRequestURI env [ 'SCRIPT_NAME' ] = "" req_uri = request . getRequestURL . to_s req_uri << '?' << qstring unless qstring . empty? env [ 'REQUEST_URI' ] = req_uri ctype = request . getContentType env [ 'CONTENT_TYPE' ] = ctype if ctype && ! ctype . empty? clength = request . getContentLength env [ 'CONTENT_LENGTH' ] = clength . to_s if clength != - 1 env [ 'rack.multiprocess' ] = false env [ 'rack.multithread' ] = true env [ 'rack.run_once' ] = false hn = request . getHeaderNames if hn . respond_to? ( :each ) hn . each do | header_name | header = header_name . upcase . tr ( '-' , '_' ) next if header == 'CONTENT_TYPE' || header == 'CONTENT_LENGTH' env [ 'HTTP_' + header ] = request . getHeader ( header_name ) end else @log . warn ( "Weird headers: [#{ hn.to_s }]" ) end env [ 'rack.input' ] = env [ 'fishwife.input' ] = convert_input ( request . input_stream , clength ) env [ 'rack.errors' ] ||= $stderr env [ 'rack.hijack?' ] = true env [ 'rack.hijack' ] = REQ_HIJACK_NOT_SUPPORTED env end
Turns a Servlet request into a Rack request hash.
Turns a Servlet request into a Rack request hash .
# The Rack request that we will pass on. # Map Servlet bits to Rack bits. #or empty string # request.getPathInfo seems to be blank, so we're using the URI. # Rack says URI, but it hands off a URL. # Java chops off the query string, but a Rack application will # expect it, so we'll add it back if present # CONTENT_TYPE/LENGTH are handled specifically, not in headers. # JRuby is like the matrix, only there's no spoon or fork(). # Populate the HTTP headers. # The output stream defaults to stderr. # All done, hand back the Rack request.
request
<not_specific>