Sha256: d6d18aed2df168ca42fd7484f19cad9c3bbd81987757e47a24e5434354f5b6f0

Contents?: true

Size: 1.44 KB

Versions: 26

Compression:

Stored size: 1.44 KB

Contents

require 'yaml'
require 'net/http'

class TestRequest
  def call(env)
    status = env["QUERY_STRING"] =~ /secret/ ? 403 : 200
    env["test.postdata"] = env["rack.input"].read
    body = env.to_yaml
    size = body.respond_to?(:bytesize) ? body.bytesize : body.size
    [status, {"Content-Type" => "text/yaml", "Content-Length" => size.to_s}, [body]]
  end

  module Helpers
    attr_reader :status, :response

    def GET(path, header={})
      Net::HTTP.start(@host, @port) { |http|
        user = header.delete(:user)
        passwd = header.delete(:passwd)

        get = Net::HTTP::Get.new(path, header)
        get.basic_auth user, passwd  if user && passwd
        http.request(get) { |response|
          @status = response.code.to_i
          @response = YAML.load(response.body)
        }
      }
    end

    def POST(path, formdata={}, header={})
      Net::HTTP.start(@host, @port) { |http|
        user = header.delete(:user)
        passwd = header.delete(:passwd)

        post = Net::HTTP::Post.new(path, header)
        post.form_data = formdata
        post.basic_auth user, passwd  if user && passwd
        http.request(post) { |response|
          @status = response.code.to_i
          @response = YAML.load(response.body)
        }
      }
    end
  end
end

class StreamingRequest
  def self.call(env)
    [200, {"Content-Type" => "text/plain"}, new]
  end

  def each
    yield "hello there!\n"
    sleep 5
    yield "that is all.\n"
  end
end

Version data entries

26 entries across 26 versions & 11 rubygems

Version Path
kastner-rack-0.3.186 test/testrequest.rb
kjvarga-rack-1.0.0 test/testrequest.rb
p8-castronaut-0.6.1.1 vendor/rack/test/testrequest.rb
qoobaa-rack-1.0.0.1 test/testrequest.rb
qoobaa-rack-1.0.2 test/testrequest.rb
relevance-castronaut-0.6.0 vendor/rack/test/testrequest.rb
relevance-castronaut-0.6.1 vendor/rack/test/testrequest.rb
relevance-castronaut-0.7.4 vendor/rack/test/testrequest.rb
relevance-castronaut-0.7.5 vendor/rack/test/testrequest.rb
timocratic-rack-1.0.0 test/testrequest.rb
nbudin-castronaut-0.7.5 vendor/rack/test/testrequest.rb
middleman-0.12.2 lib/middleman/vendor/gems/gems/rack-1.0.1/test/testrequest.rb
middleman-0.12.1 lib/middleman/vendor/gems/gems/rack-1.0.1/test/testrequest.rb
middleman-0.12.0.pre3 lib/middleman/vendor/gems/gems/rack-1.0.1/test/testrequest.rb
middleman-0.12.0.pre2 lib/middleman/vendor/gems/gems/rack-1.0.1/test/testrequest.rb
middleman-0.12.0.pre lib/middleman/vendor/gems/gems/rack-1.0.1/test/testrequest.rb
middleman-0.10.17 vendor/gems/gems/rack-1.0.1/test/testrequest.rb
middleman-0.10.16 vendor/gems/gems/rack-1.0.1/test/testrequest.rb
middleman-0.10.15 vendor/gems/gems/rack-1.0.1/test/testrequest.rb
rackjour-0.1.8 vendor/gems/gems/rack-1.0.1/test/testrequest.rb