Sha256: 61ff3ac431fe1e44a4db0568aa9b9e08b017b5c92a553cf39f0651bda836aa5f

Contents?: true

Size: 1020 Bytes

Versions: 7

Compression:

Stored size: 1020 Bytes

Contents

# frozen_string_literal: true

class TestApp < Sinatra::Base
  set :root, File.dirname(__FILE__)
  set :public_folder, -> { File.join(root, "static") }

  get "/status_code/:code" do
    status params[:code]
  end

  get "/headers/:header" do
    request.env[params[:header]]
  end

  get "/hello_world" do
    headers "hello" => "world"
    "Hello world!"
  end

  get "/body/:content" do
    params[:content]
  end

  get "/redirect_loop" do
    redirect to "/redirect_loop"
  end

  get "/redirect" do
    n = params[:times].to_i
    n.zero? ? "You arrived!" : (redirect to "/redirect?times=#{n - 1}")
  end

  get "/malformed_redirect" do
    redirect to "hptt://bro.ken"
  end

  get "/json/:file" do
    content_type "application/json"
    send_file(static_file("json/#{params[:file]}"))
  end

  get "/xml/:file" do
    content_type "application/xml"
    send_file(static_file("xml/#{params[:file]}"))
  end

private

  def static_file(file_path)
    File.expand_path(file_path, settings.public_folder)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
wayfarer-0.4.6 spec/support/test_app.rb
wayfarer-0.4.5 spec/support/test_app.rb
wayfarer-0.4.4 spec/support/test_app.rb
wayfarer-0.4.3 spec/support/test_app.rb
wayfarer-0.4.2 spec/support/test_app.rb
wayfarer-0.4.1 spec/support/test_app.rb
wayfarer-0.4.0 spec/support/test_app.rb