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

Some API responses are text/plain, rather than JSON #867

Open
algernon opened this issue Feb 2, 2024 · 1 comment · May be fixed by #988
Open

Some API responses are text/plain, rather than JSON #867

algernon opened this issue Feb 2, 2024 · 1 comment · May be fixed by #988

Comments

@algernon
Copy link

algernon commented Feb 2, 2024

While writing some tests for my library, I stumbled upon another minor inconsistency: trying to retrieve a non-existent post will always return a response in text/plain, whether authenticated or not.

Reproduction:

❯ curl -i http://localhost:8080/api/posts/0 -H "content-type: application/json"
HTTP/1.1 404 Not Found
Cache-Control: public, max-age=604800, immutable
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Thu, 09 Nov 2023 18:19:02 GMT
Content-Length: 19

404 page not found

Same thing happens when I try to post an update, or delete a non-existing post: the response is in text/plain. Looks like the entire /api/posts/{id} endpoint returns text/plain when the id doesn't exist, rather than the usual json.

@thebaer
Copy link
Member

thebaer commented Feb 5, 2024

Looks like this is caused by this line, where we're expecting the ID to be 10 characters long:

posts.HandleFunc("/{post:[a-zA-Z0-9]{10}}", handler.AllReader(fetchPost)).Methods("GET")

Since the ID for /api/posts/0 is only one character, WF falls back to the default handlers. There's no reason we need to be so strict, so we can probably just remove the regex here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants