NanoHttpd / nanohttpd

Tiny, easily embeddable HTTP server in Java.
http://nanohttpd.org
BSD 3-Clause "New" or "Revised" License
6.95k stars 1.7k forks source link

Split IHTTPSession in half, read request bodies as a whole entity, automatically parsing the body #406

Open LordFokas opened 7 years ago

LordFokas commented 7 years ago

Alright so... so far the HTTP session has acted as both a connection and a request, the request part being reused once each request arrives. This has brought us to the current situation:

Therefore I propose to split it in the following way: image

Each Request is read in the getNextRequest() method, that replaces execute() and parseBody(), automatically reading the full body and placing it in an appropriate place. The Request knows it's parent Connection, being able to link back to it in case you need to interact with the socket or read connection-wide informations.

We don't need to worry about the number of objects we're creating because the Garbage Collectors are smart enough to reuse them, since we'll be creating Request objects over and over and over again.

=========================================================

This will take care of the following issues:

396 - getHostName() may cause a delay when client connects

376 - make parseBody() non-optional

364 - getQueryParameterString is sticky

358 - Simplify the way Requests are passed to serve()

356 - Send the request twice very fast,the second time will get "syntax error" message

322 - Request takes very long on DHCP

318 - Very slow loading in version 2.3.0

314 - Choosing not to session.parseBody() of certain requests causes body to carry over to next request

211 - read post body in chunked mode

Plus it will likely also fix some speed issues people have been complaining about.

=========================================================

I think I've just hit the Mother Lode here. This looks like the biggest, baddest, nastiest cause of issues we've ever had.