dev.mccue/reasonphrase
dev.mccue.reasonphrase
bowbahdoe/reasonphrase
reasonphrase
is a library that provides a lookup from an HTTP Status Code (like 200
) to an HTTP Reason Phrase (like OK
).
Reason phrases are a mostly unused part of the HTTP protocol but, if you need to pick one anyway, you might as well pick a standard one.
In most situations, your web server will automatically pick a reason phrase based on the status code of a response.
A notable exception to this is Microhttp, which exposes the reason phrase directly in its Response
record.
So if you are using Microhttp, or some other minimal server, then this library will be of use.
import org.microhttp.EventLoop;
import org.microhttp.Response;
import org.microhttp.Header;
import dev.mccue.reasonphrase.ReasonPhrase;
void main() throws Exception {
= new EventLoop((request, callback) -> {
var eventLoop .accept(new Response(
callback200,
.forStatus(200),
ReasonPhraseList.of(new Header("Content-Type", "text/plain")),
"Hello, world".getBytes()
));
});
.start();
eventLoop.join();
eventLoop}