Sha256: 52939d0bc0dcbd1966d78be98bb3cc31eef8479ec22305c38abaa71c2f2e52d3

Contents?: true

Size: 1.01 KB

Versions: 30

Compression:

Stored size: 1.01 KB

Contents

require_relative "../spec_helper"

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

30 entries across 30 versions & 1 rubygems

Version Path
roda-3.28.0 spec/plugin/request_headers_spec.rb
roda-3.27.0 spec/plugin/request_headers_spec.rb
roda-3.26.0 spec/plugin/request_headers_spec.rb
roda-3.25.0 spec/plugin/request_headers_spec.rb
roda-3.24.0 spec/plugin/request_headers_spec.rb
roda-3.23.0 spec/plugin/request_headers_spec.rb
roda-3.22.0 spec/plugin/request_headers_spec.rb
roda-3.21.0 spec/plugin/request_headers_spec.rb
roda-3.20.0 spec/plugin/request_headers_spec.rb
roda-3.19.0 spec/plugin/request_headers_spec.rb
roda-3.18.0 spec/plugin/request_headers_spec.rb
roda-3.17.0 spec/plugin/request_headers_spec.rb
roda-3.16.0 spec/plugin/request_headers_spec.rb
roda-3.15.0 spec/plugin/request_headers_spec.rb
roda-3.14.1 spec/plugin/request_headers_spec.rb
roda-3.14.0 spec/plugin/request_headers_spec.rb
roda-3.13.0 spec/plugin/request_headers_spec.rb
roda-3.12.0 spec/plugin/request_headers_spec.rb
roda-3.11.0 spec/plugin/request_headers_spec.rb
roda-3.10.0 spec/plugin/request_headers_spec.rb