Visualising redirects with Org mode

I often find myself testing and documenting things from Org mode, and have a cool trick one can use to peek at reponse headers from a source block.

curl won’t show you headers by default, but does provide multitudinal options for printing additional information. Varying levels of verbosity are obvious choices when frolicking on the command line.

With Org however, we can do better.

#+begin_src sh :results output verbatim :exports both :wrap src http
curl 2>&1 --silent --dump-header - \
  "" \
  | tr -d '\r'

We create a source block and specify that we’re interested in the output verbatim. We export both the source code and the results, and we wrap those results in another source block with syntax highlighting provided by http-mode.

We redirect curl’s stderr output to stdout and silence all but the headers we dump. Use of tr does away with pesky line endings from cross-platform quackery.

#+begin_src http
HTTP/2 308
cache-control: public, max-age=0, must-revalidate
content-type: text/plain
date: Mon, 22 Jan 2024 22:47:32 GMT
location: /til/postgresql-vectors-and-clojure
refresh: 0;url=/til/postgresql-vectors-and-clojure
server: Vercel
strict-transport-security: max-age=63072000
x-vercel-id: lhr1::r92qh-1705963652656-3a85ce5dc2aa


And with that, we can see my fat-fingered filename is no longer polluting what should be a pretty URL.