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

Addon should be active depending on content type of final request to page #172

Closed
tlaundal opened this issue Aug 19, 2020 · 2 comments · Fixed by #173
Closed

Addon should be active depending on content type of final request to page #172

tlaundal opened this issue Aug 19, 2020 · 2 comments · Fixed by #173

Comments

@tlaundal
Copy link
Contributor

When navigating to an URL that responds with 303 See Other and Content-Type: application/json, JSONView tries to interpret the data at the redirected resource as JSON regardless of the content type returned with the redirected resource.

Example flow:

  1. User navigates to example.com/redirect
  2. example.com responds with 303 See Other, Content-Type: application/json and Location: https://example.com/resource
  3. Browser requests example.com/resource
  4. example.com responds with 200 OK, Content-Type: text/html and a webpage
  5. JSONView tries to display the webpage as JSON, and fails with the error "There was an error parsing the JSON document. The document may not be well-formed."

I've experienced this in an enterprise app, so I can not give an example link to a page with an example of this, unfortunately.

@bhollis
Copy link
Owner

bhollis commented Aug 19, 2020

If there's a way to get at that, I'd appreciate a PR that does that.

@tlaundal
Copy link
Contributor Author

tlaundal commented Aug 20, 2020

If there's a way to get at that, I'd appreciate a PR that does that.

I might take a shot at solving it some time. For now I just wanted to report it :)

Edit: After a super quick look at the code, it might work to just filter away 3XX responses somewhere near here: https://github.com/bhollis/jsonview/blob/master/src/background.ts#L53

tlaundal pushed a commit to tlaundal/jsonview that referenced this issue Aug 22, 2020
The content type header is irrelevant for redirect (status 300 to 400)
responses, as they do not say anything about the content type of the
actual resource they redirect to.

This commit makes the extension silently ignore redirect responses. The
resource at the end of the redirect is still handled properly.

No special consideration is taken for status code 300 which will not
make the browser create a new request, as the response body for these
responses should already be made for display to the user.

Fixes bhollis#172
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants