Strange behavior with a little racks app in thin


#1

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?
blublublub”]

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?


#2

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
hoConnection 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


#3

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

If you see

Content-Length: content[0].length

then you know there’s a problem :slight_smile:


#4

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.