while it’s a good idea to understand how to use TCP socket directly. Trying to reinvent http request parsing is a waste of time.
You could do something simpler maybe. one thing i noticed from your code is it can only process one request at any given time. A real server would start a thread for each connexion.