version 2020/05/01

A project log for micro HTTP server in C

Connect your browser to your smart devices, using a minimalist HTTP compliant server written in POSIX/C

yann-guidon-ygdesYann Guidon / YGDES 05/01/2020 at 20:590 Comments

I uploaded a newer version that seems to solve some issues I discovered these last days. I found a condition that triggered a double close, for example, and a more worrying endless loop when the peer closes the socket before the server... POSIX sockets are really as painful as they seem !

I reworked some functions and it changed the behaviour of the browsers, I got the following  effects :


Remote (over the internet) :

The local scores are those that matter because HTTaP is not intended to be used over the WWW (though of course it would be better if it could but then multi-threading would become necessary, and it's out of scope). Normally, HTTaP is used over a simple LAN.

The change is that serving the pages is done in priority, while checking the incoming connections has lost its precedence.

Another problem is when receiving zero-sized packets. TCP/IP seems to allow this, and it might help with sending keepalive packets. However the BSD standards indicate the closure of a socket by reading 0 bytes. It is no obvious/simple to verify this with a different method (I considered testing with poll() and checking for POLLOUT in the .revent...) so I have chosen to simply leave this case alone, and close the socket.

Due to interferences with Facebook's URL hijacks, I added a special HTTaP 400 error message with a link to the main page.

For example will return an error 400 with the following clear text message:

HTTaP key not found.
main site

The above links work well with Chrome (to the extent that it displays the page). However Firefox will fire 10 sockets and send no data on the first one... and then that connection times out after all the others have been rejected. WTF ???

On the server side, there are two big things to code now :

The second part is partially written so it will be done first, but having the HTTaP keys build API would help too...

Then I'll start to write more JS to be included in HTML, to help with loading the extra external elements (a for-loop to sequentially load the images from reading the HTML source code)