Sha256: 6330c22182df3039ca52bce288e84c2ec4548a9edf0f82c0ae8f8a5456dc6d4c

Contents?: true

Size: 747 Bytes

Versions: 4

Compression:

Stored size: 747 Bytes

Contents

require 'rubygems'
require 'sinatra'

set :port, 3001

helpers do
  def protected!
    unless authorized?
      response['WWW-Authenticate'] = %(Basic realm="BigBench TestWebServer")
      throw(:halt, [401, "Not authorized\n"])
    end
  end

  def authorized?
    @auth ||=  Rack::Auth::Basic::Request.new(request.env)
    @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['admin', 'secret']
  end
end

# Base HTTP Verbs
get "/" do
  "Test"
end

put "/" do
  "Test"
end

post "/" do
  "Test"
end

delete "/" do
  "Test"
end

# Basic Auth URL
get "/basic/auth" do
  protected!
  "Test"
end

# Needs Body Params
post "/post/content" do
  status 406 unless params[:name] == "bigbench" and params[:id] == "1"
  "Test"
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bigbench-0.0.5 spec/lib/test_web_server.rb
bigbench-0.0.4 spec/lib/test_web_server.rb
bigbench-0.0.3 spec/lib/test_web_server.rb
bigbench-0.0.2 spec/lib/test_web_server.rb