Left here for archival purposes.

User avatar
By MK1888
#11751 I thought it only signified "done" with a GET request? I don't use double "\r\n" at all in my web server scripts.

EDIT: Interesting. Unknowingly, I have been using "\n\n" instead of "\r\n\r\n". They both seem to work the same. And, yes, a single "\r\n" does not work.
User avatar
By dpwhittaker
#11761 The blank line separates the headers from the body of the response. In this case, there is just the one special header with the http response code and version.

Browsers are pretty lenient when it comes to the http standard, and this thread is just one example of how that leniency is bad.... different browsers are lenient in different ways and to different extents.
User avatar
By dadangluki
#11766
Pram wrote:
So how do I get to know my content lenght in bytes ?



Just do this:
Code: Select allCONTENT="HALLO WORLD!"
LENGTH=tostring(string.len(CONTENT))
RESPONSE=string.format("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\nContent-Length: %s\r\n\r\n%s\r\n\r\n" ,LENGTH,CONTENT)
User avatar
By dadangluki
#11767 In my experience, between one web browser an other have different behavior . One thing may work on firefox but not in chrome or IE. So my conclusion is we need to follow standard HTTP specification.
If we use Chrome, miss content-length will be reported as error. We can check in chrome developer tools console. This as well as android browser. If we miss content-length, android browser sometime will still waiting for data even if the server close the connection.
"Connection: close" is important to inform web browser that the server intend to close the connection after data transmission. If we miss this (we put Connection: keep alive) but the server close the connection, at the first time android browser should work, but not in the second time. In the third time its should work again, but not in fourth time, and so on.