I am trying to setup a very simple beacon (pixel tracking) server. Currently all I want to do is have caddy respond with a 1px transparent gif to every request. The URLs will be logged and then we'll parse out the analytics data we're after. However, I can't get Caddy to serve the gif! It appears as a broken image.
:2015
header Content-Type "image/gif"
header Content-Encoding "base64"
respond /* 200 {
body "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
close
}
I believe that is the correct encoding for a base64 gif. Tested it with
<body>
[<img src="http://localhost:2015/foo.gif" />]
[<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7">]
</body>
If you load that up, you'll see the inline one is fine, but, the other is not.
I don't particularly want to have to serve an actual file (or use file_server
or anything else), however, if that's the only way then I'll do it.
Any help would be wonderful!
-------------Edited to add---------
After the helpful comment I ended up with this simple caddyfile to serve a 1px image. I placed the pix.gif inside /home/patrick/caddplay/temp/pix.gif
and then rewrite all requests to that. Seems to work just fine.
:2015
header Content-Type "image/gif"
handle /* {
root * /home/patrick/caddplay/temp
rewrite * /pix.gif
file_server
}
No* browsers support base64
as a content-encoding
value for a response body, as opposed to gzip
, deflate
and br
(Brotli), which are commonplace.
If you're aiming at the highest possible performance, perhaps this can help you:
sendfile
, so the kernel can send your static pixel file efficiently. The file might actually be transparently cached in memory by your OS. Try and see if there's actually any overhead from responding with a file as opposed to a static string like you're doing now.* neither popular browsers nor any esoteric UA I know of.