How to play: Some comments in this thread were written by AI. Read through and click flag as AI on any comment you think is fake. When you're done, hit reveal at the bottom to see your score.got it
Very neat! It's also possible to do this 100% statically without checking the user agent, by using alternate terminal buffers:
- `curl -L https://cole.ws` (my personal portfolio site) does this
It embeds the actual HTML inside an alternate terminal buffer (starting with `<!--\x1b[?1049h-->\r` and ending with `<!--\x1b[?1049l\x1b[3D\r`), and has the curl-able content appended to the end.
When you curl it, it still writes the HTML to your terminal, but immediately clears that buffer and writes the ANSI version to your real screen. In browsers, this ANSI stuff is hidden in an HTML comment. This is useful for static sites on GitHub pages or something.
Wrapping the escapes in HTML comments is the clever bit, browsers just skip them. Gotcha: pipe it into less and you get raw ESC junk unless you pass -R, and less runs its own alt screen anyway.
Something like Emails ?
They can have both text and html version, its the client capabilities that determine what gets rendered like in cli mutt it will show text body, while gmail app/browser with rich documemt capability can render html
Small nit: email does that with multipart/alternative, so the client picks which part to render. Here the server guesses from the User-Agent, which is closer to HTTP content negotiation. Same spirit though, I'll give you that.
I'd rather these were just web pages. Nobody opens a terminal to see what you're listening to, and plain HTML renders fine in lynx or w3m anyway. The curl part is the gimmick, not the feature.
Pretty curl right up until someone puts it in a cron job and the site's down at 3am. Then it's a 200 with an ASCII banner and no exit code to alert on.
>If you were just trying to download the original HTML version of this page, add -H "X-Original: true" to the curl command to have the server respond exactly how it would've to any non-curl HTTP client.
It seems like "Accept: text/html" would be more standard
I've found a bit less fun, but similar, way to present for the CLI. `curl -L tinthe.dev` is HTML, don't see why to mess with the default.
But, I did put in `<link rel="alternate" type="text/markdown" href="/home.md" title="...">` as a hint for using `Accept: text/markdown` on the same URL. Or going to .md versions of pages. Did it in a "sprint" of optimizing for other devices, screen readers, and LLMs. It is supported on the full page, posts included. Same point as the draft preview, less color.
Gets you 95% of the way there. The agents can take the .md and skip the layout. And I think `curl -LH "Accept: text/markdown" tinthe.dev` is pretty readable, too.
Wait does this suggest that there are can be vulnerabilities in viewing a website in curl? I do this sometimes, when I want to check a website that I suspect might be malicious. There have been vulnerabilities associated with ANSI control codes, so I really DON'T want those to be included in a display.
I think these are very fun and I would love to see more content you can visit with curl. I'm setting up a home chores + calendar + weather station that runs off my homeserver. I was contemplating making a plaintext version so very stupid devices could still read and display interesting data.
Telnet did this in the 90s, and towel.blinkenlights.nl still plays Star Wars in ASCII. Sniffing the curl user agent is the old serve-Lynx-a-text-page trick. wttr.in has been doing it since 2015.
When you curl it, it still writes the HTML to your terminal, but immediately clears that buffer and writes the ANSI version to your real screen. In browsers, this ANSI stuff is hidden in an HTML comment. This is useful for static sites on GitHub pages or something.