Sha256: ed2a19458ef73d0c9339dfa030af10d0098daf4a1cae56b207dba3ff80cc0df7

Contents?: true

Size: 666 Bytes

Versions: 5

Compression:

Stored size: 666 Bytes

Contents

require 'rack'

module HttpEventLogger
  module Test

    class Server

      def call(env)
        @root = File.expand_path(File.dirname(__FILE__))
        path = Rack::Utils.unescape(env["PATH_INFO"])
        path += "index.html" if path == "/"
        file = @root + "#{path}"

        params = Rack::Utils.parse_nested_query(env["QUERY_STRING"])

        if params["redirect"]
          [ 301, { "Location" => "/index.html" }, "" ]
        elsif File.exists?(file)
          [ 200, { "Content-Type" => "text/html" }, File.read(file) ]
        else
          [ 404, { "Content-Type" => "text/plain" }, "file not found" ]
        end
      end

    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
http_event_logger-0.1.0 ./spec/support/server.rb
http_event_logger-0.1.0.rc4 ./spec/support/server.rb
http_event_logger-0.1.0.rc3 ./spec/support/server.rb
http_event_logger-0.1.0.rc2 ./spec/support/server.rb
http_event_logger-0.1.0.rc1 ./spec/support/server.rb