#87 ✓resolved
Andreas Karlsson

Missing SERVER_NAME if Host header is missing

Reported by Andreas Karlsson | November 9th, 2008 @ 02:08 PM | in 1.1

Rack::Lint complains about missing requried env key SERVER_NAME when the host field is left out.

The host header is required in HTTP 1.1, but not in HTTP 1.0. According to the Rack spec http://rack.rubyforge.org/doc/fi... the SERVER_NAME key is required, but I am not sure what it should be if no hostname is specified in the HTTP request.

The error message is:


!! Unexpected error while processing request: env missing required key SERVER_NAME

Steps to reproduce.

Use the Rack application below.


# hello_world.ru
app = proc do |env|
  [200, {'Content-Type' => 'text/plain'}, ["Hello World!\n"]]
end

use Rack::Lint

run app

thin start -R hello_world.ru

I personally use netcat to send my HTTP requests but if you do not have it installed telnet works just fine, if a bit more tedious.


echo -e -n 'GET / HTTP/1.0\r\n\r\n' | netcat localhost 3000

This is request does not give any errors:


echo -e -n 'GET / HTTP/1.0\r\nHost: localhost\r\n\r\n' | netcat localhost 3000

Comments and changes to this ticket

  • Andreas Karlsson

    Andreas Karlsson November 10th, 2008 @ 03:30 AM

    I have now checked what Webrick does. It sets it to "localhost" if the host header is missing.

    
    app = proc do |env|
      [200, {'Content-Type' => 'text/plain'}, ["SERVER_NAME: #{env['SERVER_NAME']}\n"]]
    end
    
    run app
    
    
    HTTP/1.1 200 OK
    Connection: close
    Date: Mon, 10 Nov 2008 08:28:12 GMT
    Content-Type: text/plain
    Server: WEBrick/1.3.1 (Ruby/1.8.6/2008-03-03)
    Content-Length: 23
    
    SERVER_NAME: localhost
    

    Is this a correct solution?

  • macournoyer

    macournoyer November 10th, 2008 @ 09:16 AM

    • Milestone changed from Future to 1.1
    • State changed from “new” to “open”

    defaulting to localhost sounds like the most obvious thing to do.

    thx for reporting Andreas!

  • macournoyer

    macournoyer December 16th, 2008 @ 09:06 PM

    • State changed from “open” to “resolved”

    (from [7c8e416848e2dfc8f1fb594997be640cf8f398b2]) Defaults SERVER_NAME to localhost like webrick does [#87 state:resolved] http://github.com/macournoyer/th...

  • macournoyer

    macournoyer March 16th, 2009 @ 09:45 PM

    (from [af9b7d0b755a4622a73b4e461a06934d0b9449d7]) Merge branch 'master' of git://github.com/macournoyer/thin into async_for_rack

    • 'master' of git://github.com/macournoyer/thin: Add hostingrails to users page changelog entry for last patch thin.c#http_field : omit parsing #defined string Defaults SERVER_NAME to localhost like webrick does [#87 state:resolved] Add changelog entry for last merge Fix spec failing cause of newer version of Ragel skiping some useless chars when parsing. dont need to namespace macros regen parser with namespaced functions just making sure to namespace the parser requiring mongrel breaks the tests namepsacing namespacing ragel stuff Add gemspec file for github No need for COMMITTERS file anymore Update site users page http://github.com/macournoyer/th...

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

People watching this ticket

Referenced by

Pages