cheat.sh
cheat.sh copied to clipboard
Send HTTP 404 when a sheet doesn't exist
trafficstars
I wanted to check if a few cheat sheets exist on cht.sh or not. The right way to do this would be via HTTP status codes, so I fired up a few HEAD requests. But cht.sh always returns 200 - even when sheets don't exist.
❯ curl --head http://cht.sh/kdialog
HTTP/1.1 200 OK
Server: nginx/1.13.12
Date: Wed, 20 May 2020 16:38:39 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 107
Connection: keep-alive
Strict-Transport-Security: max-age=63072000; includeSubdomains
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
❯ curl http://cht.sh/kdialog
Unknown topic.
Do you mean one of these topics maybe?
* dig 60
* git-log 57
* killall 57
From the headers, it's hard to see if the cheatsheet exists on the repo or not.
Content-Length could be an indicator.
But I think the right thing would be to return 404 along with the message?
Yes, it is a bug, I confirm it
Also for this situation: https://cht.sh/rust/flush+stdout/1
$ http https://cht.sh/rust/flush+stdout/1
HTTP/1.1 200 OK
Connection: keep-alive
...
X-Frame-Options: DENY
/*
* 404 NOT FOUND
*
* Unknown cheat sheet. Please try to reformulate your query.
* Query format:
*/
/LANG/QUESTION
But this is also a different issue