Skip to content

Send HTTP 404 when a sheet doesn't exist #198

@dufferzafar

Description

@dufferzafar

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?

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions