[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Strange behavior with a little racks app in thin

mrpink

1/7/2009 11:06:00 AM

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?
3 Answers

Brian Candler

1/7/2009 1:08:00 PM

0

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 :-)
--
Posted via http://www.ruby-....

mrpink

1/7/2009 3:13:00 PM

0

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

Brian Candler

1/8/2009 9:51:00 AM

0

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.
--
Posted via http://www.ruby-....