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

Phase transition idea. #76

Open
greim opened this issue Feb 25, 2016 · 3 comments
Open

Phase transition idea. #76

greim opened this issue Feb 25, 2016 · 3 comments

Comments

@greim
Copy link
Owner

greim commented Feb 25, 2016

Idea: add a "phaseless" feature which would allow you to do:

proxy.intercept({
  // same options, except "phase" is now optional
}, function*(request, response) {
  // if you omitted the phase option, then you must
  // manually step from phase to phase.

  // you start out in the 'request' phase
  yield request.toServer();
  // you are now in the 'request-sent' phase
  yield response.fromServer();
  // you are now in the 'response' phase
  yield response.toClient();
  // you are now in the 'response-sent' phase
});

This would allow handling errors that happen between phases within the scope of an intercept, which currently isn't possible. Example:

proxy.intercept({
  host: 'example.com'
}, function*(request, response) {
  yield request.toServer();
  try { yield response.fromServer(); }
  catch(ex) { response.statusCode = 502; }
  yield response.toClient();
});
@greim
Copy link
Owner Author

greim commented Feb 25, 2016

@mitchhentges @sholladay @nerdbeere thoughts?

@mitchhentges
Copy link

That seems way more flexible than before, so it sounds good to me! Looking forward to nerdbeere and sholladay's input, though.

@sholladay
Copy link
Contributor

It certainly is flexible. And that is an excellent use of yield, which is pretty cool.

As for the example, I'm inclined to think that hoxy should be responsible for complying with the HTTP spec for the most part and I shouldn't have to worry about implementing that. I'm sure there are other awesome use cases, though. The only other hangup for me is that, to my eyes, this exacerbates the confusion I tried to describe in #72 related to what the request/response actually represents.

In the example, when you do response.fromServer(), you're not really going to have access to the response from the server, but instead a potentially mutated copy populated with stuff for the client. The kinds of proxies described in #48 benefit a lot from that distinction being clear and fluent.

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

3 participants