Strange behavior with a little racks app in thin

G

Guest

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?
 
B

Brian Candler

Karl said:
'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 :)
 
G

Guest

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
 
B

Brian Candler

Karl said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,802
Messages
2,569,661
Members
45,428
Latest member
ViolettePa

Latest Threads

Top