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

Retrieve a Collection API endpoint uses request content-type instead of accept header #178

Open
carbontwelve opened this issue Sep 3, 2019 · 2 comments · May be fixed by #185

Comments

@carbontwelve
Copy link

commented Sep 3, 2019

Describe the bug

When using the Retrieve a Collection API endpoint as documented here I notice that when sending a request with the Accept header correctly set to application/json the server was incorrectly returning Content-Type:text/html.

Upon looking at the source code I can see this bug is seemingly due to the following line: https://github.com/writeas/writefreely/blob/master/collections.go#L321

Steps to reproduce (if necessary)

Steps to reproduce the behavior:

  1. Request the GET /api/collections/{COLLECTION_ALIAS} API endpoint with Accept header set for application/json
  2. Server responds with HTML.

Expected behavior

The request is stating it accepts json the server should respond with content type json or HTTP 415 Unsupported Media Type if not supported. Given that the API supports returning JSON it should have responded with JSON.

The following line https://github.com/writeas/writefreely/blob/master/collections.go#L321 potentially needs amending to include the Accept header as well.

@thebaer thebaer added the bug label Sep 3, 2019

@thebaer

This comment has been minimized.

Copy link
Member

commented Sep 18, 2019

Thanks for the report!

For a first pass, we can refactor IsJSON() to accept a http.Request instead of a string and check both the Content-Type and Accept headers.

@robjloranger want to take a look?

@robjloranger

This comment has been minimized.

Copy link
Member

commented Sep 18, 2019

👍

@robjloranger robjloranger self-assigned this Sep 18, 2019

@robjloranger robjloranger referenced a pull request that will close this issue Sep 18, 2019
1 of 1 task complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.