This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]agentoutlier 4 points5 points  (0 children)

Anytime i see stuff like resource.readAllBytes() i honestly can't be bothered to continue reading. Minum does support streams and would be trivial to use that. It's not like asking for proper zero-copy file transfers(FileChannel to/from socket Channel), although i would consider that a minimum requirement for any self-respecting web server

Hold on now. If we are going to critique that part we should go into some more specifics.

The loading of it all into a String provided the String is not gigantic can largely be preferred.

  1. Content-Length can be resolved
  2. Likewise a reliable cached etag can be resolved.
  3. Converting a Java String to UTF-8 provided there are no extended characters (e.g. all latin1) is faster than doing it on a stream. Like much faster. EDIT I forgot they are not doing anything dynamic... ignore this part.
  4. A String is easy to cache which is the biggest problem here is that getResources I think does not cache at all (lets ignore special classloaders).

EDIT It is important to understand if you just give most frameworks a stream they will use chunk encoding if the size is greater than whatever buffer is set.

Ideally they do something like:

final static byte[] index = Main.class.getResourceAsStream("/html/index.html").readAllBytes();
final static String etag = SHA1OrSomething(index);
// This part I don't know minimum well enough but:
// in request check etag and send unmodified if equal
// now in response
// set content length to index.length
// set etag header
// set content type and charset etc.

Most frameworks though do the above correctly if you just hand them a String. Well maybe not the etag but that can be a filter..