NanoHttpd / nanohttpd

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

Make it easier to copy SimpleWebServer as an example #549

Closed harvv closed 5 years ago

harvv commented 5 years ago

(This is not at all critical; simply a nice-ty improvement)

Even though it isn't in "samples", the SimpleWebServer class makes a great base / example for how to make a very functional fileserver. As such, it's reasonable to copy the code into one's own package and then modify it, beyond what would be logical to do with subclassing...

however, the class uses a protected method (construct) of Response, here:

https://github.com/NanoHttpd/nanohttpd/blob/efb2ebf85a2b06f7c508aba9eaad5377e3a01e81/webserver/src/main/java/org/nanohttpd/webserver/SimpleWebServer.java#L367

...and this makes copying the class verbatim into another package problematic. Perhaps instead, just sticking to using public ways of constructing the response? maybe: r = newFixedLengthResponse(Response.Status.OK, MIME_PLAINTEXT, null, 0);

(which seems to do the same, though i'll admit i didn't test it)

just a suggestion.

harvv commented 5 years ago

oh never mind, i just noticed this is fixed in the new code (my version had the line as: new Response(Response.Status.OK, MIME_PLAINTEXT, null, 0);)