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

Closed
carbontwelve opened this issue Sep 3, 2019 · 2 comments
Assignees
Labels
bug

Comments

@carbontwelve
Copy link

@carbontwelve carbontwelve 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
Copy link
Member

@thebaer thebaer 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
Copy link
Member

@robjloranger robjloranger commented Sep 18, 2019

👍

@robjloranger robjloranger self-assigned this Sep 18, 2019
@robjloranger robjloranger mentioned this issue Sep 18, 2019
1 of 1 task complete
@thebaer thebaer closed this in #185 Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.