Today Thorsten Ball asked a simple question on Twitter:
Does something like a reverse-curl exist? A tool that allows me to listen on a socket and return one HTTP response?— Thorsten Ball (@thorstenball) October 27, 2017
After a brief exchange of tweets, I said:
Or we could write one in Go 😺— Lean (inkel) (@inkel) October 27, 2017
Twenty minutes later
lruc was born.
Oh wow! :)— Thorsten Ball (@thorstenball) October 27, 2017
It’s still very fresh and missing many features, but basically it is a web server that allows you to configure it to always respond with a custom response without too much hassle. The usage is very simple:
Usage of lruc: -addr string Address to listen for requests (default ":8080") -body - Response body. Use - to read from a stdin (default "Hello, World!") -code int HTTP response code (default 200) -content-type string Content-Type (default "text/plain")
Say that you want to create a server that always respond with a
404 Not Found and a body of
No se pudo encontrar lo que buscaba (Spanish for Couldn’t find what you were looking for (sort of)) on port 7070, then you could execute the following:
lruc -addr :7070 -code 404 -body "No se pudo encontrar lo que buscaba"
Or say that you want to always return an image, then you could do something like:
< image.png lruc -content-type image/png -body - # Or in an useless use of cat cat image.png | lruc -content-type image/png -body -
This seems like an interesting tool to keep working on, so watch
github.com/inkel/lruc for updates.
PS: did I said already that I love Go?