Sha256: e48a0268ed74eadc79686feab35b1e513092b98c4a74ad776ed4562503e71f3e

Contents?: true

Size: 1.06 KB

Versions: 14

Compression:

Stored size: 1.06 KB

Contents

require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))

describe "request_headers plugin" do
  def header_app(header_name)
    app(:bare) do
      plugin :request_headers
      route do |r|
        r.on do
          # return the value of the request header in the response body,
          # or the static string 'not found' if it hasn't been supplied.
          r.headers[header_name] || 'not found'
        end
      end
    end
  end

  it "must add HTTP_ prefix when appropriate" do
    header_app('Foo')
    body('/', {'HTTP_FOO' => 'a'}).must_equal 'a'
  end

  it "must ignore HTTP_ prefix when appropriate" do
    header_app('Content-Type')
    body('/', {'CONTENT_TYPE' => 'a'}).must_equal 'a'
  end

  it "must return nil for non-existant headers" do
    header_app('X-Non-Existant')
    body('/').must_equal 'not found'
  end

  it "must be case-insensitive" do
    header_app('X-My-Header')
    body('/', {'HTTP_X_MY_HEADER' => 'a'}).must_equal 'a'

    header_app('x-my-header')
    body('/', {'HTTP_X_MY_HEADER' => 'a'}).must_equal 'a'
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
roda-2.29.0 spec/plugin/request_headers_spec.rb
roda-2.28.0 spec/plugin/request_headers_spec.rb
roda-2.27.0 spec/plugin/request_headers_spec.rb
roda-2.26.0 spec/plugin/request_headers_spec.rb
roda-2.25.0 spec/plugin/request_headers_spec.rb
roda-2.24.0 spec/plugin/request_headers_spec.rb
roda-2.23.0 spec/plugin/request_headers_spec.rb
roda-2.22.0 spec/plugin/request_headers_spec.rb
roda-2.21.0 spec/plugin/request_headers_spec.rb
roda-2.20.0 spec/plugin/request_headers_spec.rb
roda-2.19.0 spec/plugin/request_headers_spec.rb
roda-2.18.0 spec/plugin/request_headers_spec.rb
roda-2.17.0 spec/plugin/request_headers_spec.rb
roda-2.16.0 spec/plugin/request_headers_spec.rb