somealiassoitwillstopaskingqs
2013-03-29 11:48:34 UTC
Hi all,
I have been playing around with io for a little while now. I have been trying to understand it better by expanding the example given for a basic webserver
For some reason the if statement testing for the request path ending in a / seems to completely stop it working. i can't work out what i am doing wrong.
port := 8000
WebRequest := Object clone do(
handleSocket := method(aSocket,
"[server] handling request\n" print
aSocket streamReadNextChunk
request := aSocket readBuffer
request print
requestPath := request betweenSeq("GET "," HTTP")
"[server] #{requestPath}\n" interpolate print
lastChar := requestPath exSlice(-1)
lastChar print
if(lastChar == "/", requestPath := "/index.html")
requestPath print
f := File with(requestPath)
if(f exists,
f streamTo(aSocket)
,
aSocket streamWrite("not found")
)
aSocket close
)
)
WebServer := Server clone do(
setPort(8000)
handleSocket := method(aSocket,
WebRequest clone asyncSend(handleSocket(aSocket))
)
)
"[server] starting on port: #{port}\n" interpolate print
WebServer start
Also the prints around the if don't seem to do anything.
I have been playing around with io for a little while now. I have been trying to understand it better by expanding the example given for a basic webserver
For some reason the if statement testing for the request path ending in a / seems to completely stop it working. i can't work out what i am doing wrong.
port := 8000
WebRequest := Object clone do(
handleSocket := method(aSocket,
"[server] handling request\n" print
aSocket streamReadNextChunk
request := aSocket readBuffer
request print
requestPath := request betweenSeq("GET "," HTTP")
"[server] #{requestPath}\n" interpolate print
lastChar := requestPath exSlice(-1)
lastChar print
if(lastChar == "/", requestPath := "/index.html")
requestPath print
f := File with(requestPath)
if(f exists,
f streamTo(aSocket)
,
aSocket streamWrite("not found")
)
aSocket close
)
)
WebServer := Server clone do(
setPort(8000)
handleSocket := method(aSocket,
WebRequest clone asyncSend(handleSocket(aSocket))
)
)
"[server] starting on port: #{port}\n" interpolate print
WebServer start
Also the prints around the if don't seem to do anything.