Uhh some questions on my HTTPd implementation...

Dave Cragg dcragg at lacscentre.co.uk
Tue Oct 21 07:55:08 EDT 2003


At 12:38 pm -0200 21/10/03, Andre Garzia wrote:
>Hi Folks,
>
>someone using my httpd server implementation or with better
>understanding of the http protocol can answer this question:
>
>Why opening http://localhost:8080/ on safari/mozilla works fine full
>of images and stuff and this code
>
>on mouseUp
>    get URL "http://localhost:8080/"
>    set the htmlText of field 1 to it
>end mouseUp
>
>does not work?!!?!? it works for www.yahoo.com and others....

Your server isn't writing any http headers. It looks like the other 
browsers are more forgiving than libUrl about this.

At the very least, you need to supply a line like this:

HTTP/1.1 200 OK

followed by crlf & crlf followed by your data.

Try adding this function at the bottom of your script:

function OKHeaders @pData
   put "HTTP/1.1 200 OK" & crlf into tRetVal
   put "Content-Type: text/html" & clrf after tRetVal
   put "Content-Length: " & length(pData)  after tRetVal
   return tRetVal
end OKHeaders

Then in your script where you write the response to the socket, use 
the function to create the headers. For example, at the end of the 
serverRead handler, try changing to this:

-------------------------------------------
--- Well it's not a substack, let's see if we can find it

   put "binfile:" & the defaultFolder & "/html/" & tRequestedDoc into tURL
   put  the defaultFolder & "/html/" & tRequestedDoc into tPath

   if there is a file tPath then
     put url tUrl into tData
     write OKHeaders(tData) & crlf & crlf & tData to socket SocketID
   else
     get the cError404 of me
     replace "%FILE%" with tRequestedDoc in it
     write it to socket socketID
   end if

   close socket socketID
end serverread
-------------------------------------------
You'll have to make similar changes where you return data from a 
substack. You'll also need similar headers for things like 404 errors.

Cheers
Dave


More information about the Use-livecode mailing list