cpp-netlib/cpp-netlib — pull request #302 by nico159 (2013-09-15 23:18:17+00:00)
Title: Hacky HTTP 1.1 persistent connection model for the sync server

The code it's absolutely hacky, and it's intended only as a prototype

The intention is port sync server to the HTTP 1.1 persistent connection model, with pipeling support

As I repeat myself, the code is hacky

request_builder keep the state of each single request, and assign a status per request:
NEED_MORE_DATA <-The current request is complete
COMPLETE <-Complete, probably a bad name -- is the last request (is not an HTTP 1.1 request, or content-length is not present, or if Connection is close
WAIT_FOR_ANOTHER_REQUEST <-Is not the last request, client can issue a new one
BAD_REQUEST <-Classic bad request

sync_connection keeps a list of request (the idea is not going to deallocate old request buffer while we are going to process the next)

sync_request know the status of each request, and can keep goig if the request is not the last one/bad reqeust

I did change the response header for 202 so the client can know that we are a HTTP 1.1 server

The timeout is hardcoded in the code (15 seconds) and is reset each time that a sync_request get data from the client
If a request timeout, handle_close is called

As you can view, the code is not so great (a full day of hacking)...so I accept all kinds of advice

I'm not sure if there are some memory leak of not...

So in the end:
It implement HTTP 1.1 connection model
sync_timeout has a timeout so after a while that the connection has not sent data, the connection is closed
Only 200 response is HTTP 1.1
request_builder keeps sync_connection alive only if a HTTP 1.1 request, there is a length, and is not connection close
sync_connection keep a list of executed request

Problems:
Naming!
The timeout is hardcoded
Now the server resply with HTTP 1.1 all the times...
There is a possibility to DoS the server -- it keeps all the executed request
There is a possibility of a memory leak...I can't tell

So question time:
How netlib should manage both HTTP 1.0 and 1.1?
Is necessary to keep the list of executed requests? Even if we consider pipelining?
Where are other cases where in HTTP 1.1 netlib should not keep the socket open?
How we make the timeout configurable?
Testing? How?
There are some memory leak?

Some things that I didn't considered in the protocol?