HEAD is an often forgotten HTTP method (verb) that behaves just like GET, but does not return body. You use HEAD in order to check the existence of a resource (it should return 404 in case of absence) and make sure you don’t have a stale version in your cache. In that case you expect 304 Not Modified, while 200 ...
Read More »Home » Archives for Tomasz Nurkiewicz »
Writing a download server. Part III: headers: Content-length and Range
We will explore more HTTP request and response headers this time to improve download server implementation: Content-length and Range. The former signals how big the download is, the latter allows downloading files partially or continue after failure from where we started. Content-length response header Content-length response header is tremendously helpful for clients that track download progress. If ...
Read More »Writing a download server. Part II: headers: Last-Modified, ETag and If-None-Match
Caching on the client side is one of the foundations of World Wide Web. Server should inform client about validity of resources and client should cache them as eagerly as possible. Without caching the web as we see it would be insanely slow. Just hit Ctrl + F5 on any website and compare it with ordinary F5 – the latter ...
Read More »Writing a download server. Part I: Always stream, never keep fully in memory
Downloading various files (either text or binary) is a bread and butter of every enterprise application. PDF documents, attachments, media, executables, CSV, very large files, etc. Almost every application, sooner or later, will have to provide some form of download. Downloading is implemented in terms of HTTP, so it’s important to fully embrace this protocol and take full advantage of ...
Read More »How LongAccumulator and DoubleAccumulator classes work?
Two classes new in Java 8 deserve some attention: LongAccumulator and DoubleAccumulator. They are designed to accumulate (more on what does that mean later) values across threads safely while being extremely fast. A test is worth a thousand words, so here is how it works: class AccumulatorSpec extends Specification { public static final long A = 1 public static final ...
Read More »Spring: injecting lists, maps, optionals and getBeansOfType() pitfalls
If you use Spring framework for more than a week you are probably aware of this feature. Suppose you have more than one bean implementing a given interface. Trying to autowire just one bean of such interface is doomed to fail because Spring has no idea which particular instance you need. You can work around that by using @Primary annotation ...
Read More »Biological computer simulation of selfish genes
TL;DR: I did a computer simulation of behavior evolution of monkeys, continue reading to see how problem was stated originally in The Selfish Gene. First part shows my Java implementation, second part shows charted results and conclusions. The problem I read The Selfish Gene by Richard Dawkins recently, very wide-opening book despite being 40 years old. While the original text ...
Read More »CompletableFuture can’t be interrupted
I wrote a lot about InterruptedException and interrupting threads already. In short if you call Future.cancel() not inly given Future will terminate pending get(), but also it will try to interrupt underlying thread. This is a pretty important feature that enables better thread pool utilization. I also wrote to always prefer CompletableFuture over standard Future. It turns out the more ...
Read More »Journey to idempotency and temporal decoupling
Idempotency in HTTP means that the same request can be performed multiple times with the same effect as if it was executed just once. If you replace current state of some resource with new one, no matter how many times you do so, in the end state will be the same as if you did it just once. To give ...
Read More »