Sha256: bf8d19e318c56b9242b53d00a28320aa6095b48fce02d924080b2336fde65bba

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

require 'rack'
require 'pry'

module Yarn
  class RackHandler < RequestHandler

    attr_accessor :env

    def initialize(app)
      @parser = ParsletParser.new
      @response = Response.new
      @app = app
    end

    def prepare_response
      begin
        make_env
        @response.content = @app.call(@env)
      rescue Exception => e
        log e.message
        log e.backtrace
      end
    end

    def make_env
      @env = {
        "REQUEST_METHOD"    => @request[:method].to_s,
        "PATH_INFO"         => @request[:uri][:path].to_s,
        "QUERY_STRING"      => @request[:uri][:query].to_s,
        "SERVER_NAME"       => @request[:uri][:host].to_s,
        "SERVER_PORT"       => @request[:uri][:port].to_s,
        "SCRIPT_NAME"       => "",
        "rack.input"        => StringIO.new("").set_encoding(Encoding::ASCII_8BIT),
        "rack.version"      => Rack::VERSION,
        "rack.errors"       => $output,
        "rack.multithread"  => true,
        "rack.multiprocess" => true,
        "rack.run_once"     => false,
        "rack.url_scheme"   => "http"
      }
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yarn-0.0.2 lib/yarn/rack_handler.rb