Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8151427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:23:09+00:00 2026-06-06T15:23:09+00:00

The Sinatra README says : request[SOME_HEADER] # value of SOME_HEADER header Given this app:

  • 0

The Sinatra README says:

request["SOME_HEADER"]      # value of SOME_HEADER header

Given this app:

require 'sinatra'

post '/env' do
    env['HTTP_X_FOO']
end

post '/request' do 
    request['X-Foo']
end

post '/request_rack_http_format' do
    request['HTTP_X_FOO']
end

The first spec passes; the next two fail:

describe "Sinatra should place the header in" do
    before(:all) do
        header 'X-Foo', 'Bar'
    end

    example "env" do
        post '/env'
        last_response.body.should == 'Bar' #pass
    end

    example "request[]" do
        post '/request'
        last_response.body.should == 'Bar' #fail; got ""
    end

    example "request[] (rack format)" do
        post '/request_rack_http_format'
        last_response.body.should == 'Bar' #fail; got ""
    end
end

Looking at the source, Sinatra doesn’t actually do anything with []; it’s implemented in Rack as the union of GET and POST. And POST just returns the form hash. For GET it’s the query hash. In all three routes, request.params is empty.

My question: Is this a doc bug, or am I misunderstanding how to use request[]? For now, my application is working fine with the env[] method. But I want to do it “right.”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:23:11+00:00Added an answer on June 6, 2026 at 3:23 pm

    Seems to be a bug in the documentation. request[] actually retrieves the params for the request, not the header:

    https://github.com/rack/rack/blob/master/lib/rack/request.rb#L262

    def [](key)
      params[key.to_s]
    end
    

    I double checked it by testing also. Seems a bit silly, but it looks like you really can’t directly access the header in any way except through env. At least I could not figure out any other way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple Sinatra app. web.rb: require 'sinatra' get '/' do Hello end Gemfile:*
Simple sinatra app: require 'rubygems' require 'sinatra' get '/' do Hey end Then: $
I'm trying to get this Sinatra GET request to work: get '/:year/:month/:day/:slug' do end
require 'sinatra/base' class Foo < Sinatra::Base get('/foo') { 'foo' } end class Bar <
I have a Sinatra app that, boiled down, looks basically like this: class MyApp
So I have a Sinatra app that receives an XML via a HTTP POST
Sinatra app: require rubygems require sinatra get '/' do Hello world. It's #{Time.now} at
app.rb: require 'sinatra' class MyApp < Sinatra::Application enable :sessions if session[:user_id].nil? then erb :login
Currently in my Sinatra + DataMapper app, I have: require 'data_mapper' DataMapper.setup(:default, sqlite3://#{Dir.pwd}/main.db) DataMapper.setup(:comments,
I have a little Sinatra app including this module: module Sprockets module Helpers def

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.