Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dufferzafar opened this issue May 20, 2020 · 2 comments
Open

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

dufferzafar opened this issue May 20, 2020 · 2 comments
Assignees

Comments

@dufferzafar
Copy link

dufferzafar commented May 20, 2020

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?

@dufferzafar dufferzafar changed the title Detect if a cheatsheet exists or not using HTTP HEAD? Send HTTP 404 when a sheet doesn't exist May 20, 2020
@chubin
Copy link
Owner

chubin commented May 21, 2020

Yes, it is a bug, I confirm it

@tennox
Copy link

tennox commented Mar 3, 2023

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

bors bot added a commit to orhun/halp that referenced this issue Mar 17, 2023
10: fix(cheat): don't use a pager when no cheat sheet found for the command r=orhun a=figsoda

<!--- Thank you for contributing to halp! 🐙 -->

## Description

cheat.sh doesn't return 404: chubin/cheat.sh#198

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->

## How Has This Been Tested?

```console
$ cargo run plz 42
   Compiling halp v0.1.3 (/home/figsoda/halp)
    Finished dev [unoptimized + debuginfo] target(s) in 0.37s
     Running `target/debug/halp plz 42`
❤ Select operation · Show cheat sheet
Unknown topic.
Do you mean one of these topics maybe?

    * m4 50
    * p4 50
    * r2 50
    

(ノ´ヮ`)ノ*: ・゚
 Select operation ›
  Show man page
✧ Show cheat sheet
  Exit
```

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran to -->
<!--- see how your change affects other areas of the code, etc. -->

## Screenshots / Logs (if applicable)

## Types of Changes

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Documentation (no code change)
- [ ] Refactor (refactoring production code)
- [ ] Other <!--- (provide information) -->

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->

- [x] My code follows the code style of this project.
- [ ] I have updated the documentation accordingly.
- [x] I have formatted the code with [rustfmt](https://github.com/rust-lang/rustfmt).
- [x] I checked the lints with [clippy](https://github.com/rust-lang/rust-clippy).
- [ ] I have added tests to cover my changes.
- [x] All new and existing tests passed.


Co-authored-by: figsoda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants