Skip to content

Adding Promise support for "getHost". #285

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

Closed
wants to merge 1 commit into from

Conversation

OronNadiv
Copy link

@OronNadiv OronNadiv commented Sep 25, 2017

@monkpow @villadora
This PR adds support for getting hostname asynchronously using Promises. It solves #284.

@OronNadiv OronNadiv closed this Sep 25, 2017
@OronNadiv OronNadiv reopened this Sep 25, 2017
@@ -65,7 +65,7 @@ describe('decorateRequest', function() {
it('returns err to host application for processing', function(done) {
var app = express();

app.use(proxy('/reject-promise', {
app.use(proxy('httpbin.org', {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated issue. This test would always fail since host must start with http(s).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment is incorrect. Test pass today without all starting with http. Current code assumes http if http/https is not provided.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@monkpow
Copy link
Collaborator

monkpow commented Sep 28, 2017

@OronNadiv Thanks for this patch. I'm starting to review now.

@monkpow monkpow self-requested a review September 28, 2017 12:50

if (container.options.memoizeHost && container.options.memoizedHost) {
parsedHost = container.options.memoizedHost;
promise = Promise.resolve(container.options.memoizedHost);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first glance, this appears to conflict with the goal of memoizing the host.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a case where an external server defines which users should go to server A and which should go to server B. In that case, every incoming request would query that external server. I plan to cache the results (MRU + expiration), but I still need an async support to determine the target host url. Does it make sense?

port: parsed.port || (ishttps ? 443 : 80),
module: ishttps ? https : http,
};
host = (typeof host === 'function') ? host(req) : host;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dropped toString() here. investigate why.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the toString() is needed. Anyways, I moved it to line 35 to support backward compatibility.

@OronNadiv
Copy link
Author

Thanks for reviewing it @monkpow. I answered a few of your questions.

@OronNadiv OronNadiv closed this Oct 20, 2017
@OronNadiv OronNadiv deleted the promisified-host branch October 20, 2017 21:33
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 this pull request may close these issues.

2 participants