Forum: Ruby Strange behavior with a little racks app in thin

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1685f91cc5853eb465ca50aa68b91421?d=identicon&s=25 Karl Weasel (soliust)
on 2009-01-07 12:33
(Received via mailing list)
Hi,
I'm playing with thin and racks at the moment. I tried to built a really
basic application:

# test.ru
content=["Is it working?<br><b>blublublub</b>"]

app = proc do |env|
  [
    200,          # Status code
    {             # Response headers
      'Content-Type' => 'text/html',
      'Content-Length' => "content[0].length",
    },
    content[0]
  ]
end

run app



If I start it with: $ thin start -R test.ru
everything looks okay: No errors. Also when I access the webserver with
my browser I don't get no errors but the site displayed. But what seems
strange is that my browser tries to take more data than it should
actually take. So it displays the content but is trying to load even
more. But there isn't more data? Can someone explain this behavior? I'm
sure I'm doing something wrong here or?
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (candlerb)
on 2009-01-07 14:07
Karl Weasel wrote:
>       'Content-Length' => "content[0].length",

Are you sure the right-hand side should be quoted? Look at the actual
HTTP response returned. You can do this using tcpdump, wireshark, curl
-v, or even plain old telnet:

telnet 127.0.0.1 80
GET / HTTP/1.0
<hit Enter again>

If you see

Content-Length: content[0].length

then you know there's a problem :-)
1685f91cc5853eb465ca50aa68b91421?d=identicon&s=25 Karl Weasel (soliust)
on 2009-01-07 16:15
(Received via mailing list)
Thank you very much Brian that was the misstake:

$ telnet 127.0.0.1 3000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
GET / HTTP/1.0

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: content[0].length
Connection: close
Server: thin 1.0.0 codename That's What She Said

hi<br><b>ho</b>Connection closed by foreign host.


Correct syntax is "#{content[0].length}" . Without quotes thin is
giving errors when trying to access the page: !! Unexpected error while
processing request: undefined method `each' for 15:Fixnum


kind regards
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (candlerb)
on 2009-01-08 10:51
Karl Weasel wrote:
> Correct syntax is "#{content[0].length}" . Without quotes thin is
> giving errors when trying to access the page: !! Unexpected error while
> processing request: undefined method `each' for 15:Fixnum

Ah, then thin doesn't like numbers as header values.

content[0].length.to_s would be another solution.
This topic is locked and can not be replied to.