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

304 responses fail with as:'json' interceptor #104

Open
smurphy917 opened this issue Jun 26, 2018 · 3 comments
Open

304 responses fail with as:'json' interceptor #104

smurphy917 opened this issue Jun 26, 2018 · 3 comments

Comments

@smurphy917
Copy link

With an as: 'json' interceptor, Proxy attempts to JSON.parse the response body, regardless of response.statusCode. Ideally, this would be skipped and the interceptor callback would be called with some indication of the 304 status code and response.json as undefined. Even better, would be an interceptor filter on response.statusCode for response and response-sent phases. Just a thought!

@greim
Copy link
Owner

greim commented Jun 27, 2018

Have you tried mimeType? Ideally a server wouldn't use a json mime type in a 304 response, so you could do:

proxy.intercept({
  phase: 'response',
  mimeType: /json/,
  as: 'json'
}, function(req, resp, cycle) {
  // ...
});

In any case, Hoxy doesn't have the ability to filter on status code but that definitely seems like a useful feature, and fits with how filtering is done in general. It wouldn't be hard to add. Then you could do:

proxy.intercept({
  phase: 'response',
  mimeType: /json/,
  status: 200,
  as: 'json'
}, function(req, resp, cycle) {
  // ...
});

I may look into adding it when I get some time. PRs also definitely welcome too :)

@smurphy917
Copy link
Author

I agree that the server shouldn't send a application/json mimeType for a 304, but unfortunately the server I'm working with tends to do just that, and I don't control that server.

I'll try to carve out some time to put a PR together for the statusCode filtering, as well as overall better handling of empty/invalid bodies with as: 'json' interceptors.

@greim
Copy link
Owner

greim commented Jun 27, 2018

I agree that the server shouldn't send a application/json mimeType for a 304, but unfortunately the server I'm working with tends to do just that, and I don't control that server.

Hahahaha... such is life :P

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

No branches or pull requests

2 participants