Skip to content

Add specific http promise #116

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

Merged
merged 1 commit into from
Aug 31, 2016
Merged

Add specific http promise #116

merged 1 commit into from
Aug 31, 2016

Conversation

joelwurtz
Copy link
Member

@joelwurtz joelwurtz commented Aug 1, 2016

Q A
Bug fix? yes
New feature? yes
BC breaks? no
Deprecations? no
Related tickets php-http/client-common#34
Documentation
License MIT

This is not something that is meant to merge, it's to offer a point of view on this ticket php-http/client-common#34 we should accept this or not based on the final decision.

@sagikazarmark
Copy link
Member

Looking at this PR: it actually doesn't solve the problem, because you cannot make sure that these promises are returned. It only provides type safety WHEN they are used. This means that you probably can't assume that the rejection callback will receive an Http\Client\Exception instance. Am I right?

So in this case php-http/client-common#35 is still valid?

@joelwurtz
Copy link
Member Author

Yes we Will need to replace used promise in emulated client by this one

@sagikazarmark
Copy link
Member

That's okay, but even then, we cannot make sure that clients will actually use that promise, so we have to rely on the Promise interface spec, which accepts any exceptions, meaning the rejection callbacks should too. Am I wrong?

@joelwurtz
Copy link
Member Author

joelwurtz commented Aug 2, 2016

I see your point, however this behavior is already clearly specify in the dockblock :

@return Promise Resolves a PSR-7 Response or fails with an Http\Client\Exception.

We can add a HttpPromise (which extends Promise) to enforce this at code level, for me it's not a BC break since we have the same behavior as previously but exprimed at the code level and not on the docblock level (so this like a new feature and can be done in a 1.1.0 version IMO).

@joelwurtz
Copy link
Member Author

I add the interface with change to the async client

/**
* {@inheritdoc}
*
* @return HttpPromise A new resolved http promise with value of the executed callback (onFulfilled / onRejected).
Copy link
Member

Choose a reason for hiding this comment

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

This is not possible. Think about PHP 7, this line should still be public function then(callable $onFulfilled = null, callable $onRejected = null): Promise;

Copy link
Member Author

Choose a reason for hiding this comment

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

So this interface is useless ? should we remove it ?

@dbu
Copy link
Contributor

dbu commented Aug 3, 2016

imho we need to solve this by documentation and avoid people using the promise stufff in HTTPlug for other things than HTTP. a promise should be allowed to throw any exception, but further promises in the chain should not be bothered with non-http exceptions.

@joelwurtz joelwurtz force-pushed the feature/http-specific-promise branch 2 times, most recently from 95c829d to bff98e8 Compare August 3, 2016 10:12
@joelwurtz
Copy link
Member Author

a promise should be allowed to throw any exception, but further promises in the chain should not be bothered with non-http exceptions.

I agree with that, but then RejectedPromise and FulfilledPromise does not respect this principle, that's why we need HttpRejectedPromise and HttpFulfilledPromise

I remove the HttpPromise interface to not having to think about a BC Break (we can do that later) and i also add tests.

@joelwurtz joelwurtz force-pushed the feature/http-specific-promise branch from bff98e8 to 67ce613 Compare August 3, 2016 10:15
@joelwurtz
Copy link
Member Author

What should we do about that ?

@sagikazarmark
Copy link
Member

This line causes all our problems IMO: https://github.com/php-http/httplug/pull/116/files#diff-0604cd13cbcbbca1c6eb9241817bb50cR34
(In the original promises). Non-HTTP exceptions can be thrown in the plugin chain, but the line above will make sure that they are not caught.

I would say let's merge this and use it in client-common.

Also, make sure we document this properly (use the above promises and/or don't throw non-http exceptions?)

My concern regarding this change: version. We will have to increase version number. How do we handle this in provides configuration in clients? Increase version number too? Or just leave 1.0 everywhere until 2.0?

@joelwurtz
Copy link
Member Author

We will have to increase version number. How do we handle this in provides configuration in clients? Increase version number too? Or just leave 1.0 everywhere until 2.0?

The contract does not change so we don't need to upgrade the version of the virtual package, library like common-client would just have to require httplug with ^1.1.0

@sagikazarmark
Copy link
Member

Okay, I vote for merging.

WDYT @joelwurtz @Nyholm @dbu ?

@Nyholm
Copy link
Member

Nyholm commented Aug 25, 2016

I've tested this and it works. Im 👍

Im trying to figure out the implications of this. It requires updates on

  • PluginClient
  • CachePlugin
  • HttpAsyncClientEmulator
  • Doc block in Plugin, right?
  • Integration tests?
  • Doc block in HttpAsyncClient
  • In most of our test code

And our Async clients:

  • cUrl client
  • Guzzle6 adapter
  • React adapter

Question: What would the new version of HTTPlug be?

@joelwurtz
Copy link
Member Author

What would the new version of HTTPlug be?

1.1.0 It's a new feature but doesn't break BC

Yes we need to update all common-client but it's for a good reason IMO, so not so a problem

@Nyholm
Copy link
Member

Nyholm commented Aug 25, 2016

Good. =)

Yes we need to update all common-client but it's for a good reason IMO, so not so a problem

I agree.

This PR is a no brainer. 👍

@joelwurtz
Copy link
Member Author

And i checked all adapters, their are good and respect the contract as far as i have seen.

@Nyholm
Copy link
Member

Nyholm commented Aug 25, 2016

Yeah, So did I. I believe there is path versions for all packages except for php-http/httplug.

@Nyholm
Copy link
Member

Nyholm commented Aug 31, 2016

I voted for merge, so did Mark and Joel. David chose to abstain. (See slack).

I will merge this PR. Thank you @joelwurtz!

@Nyholm Nyholm merged commit 5343ca1 into master Aug 31, 2016
@sagikazarmark sagikazarmark deleted the feature/http-specific-promise branch August 31, 2016 07:43
@sagikazarmark
Copy link
Member

Does this invalidate php-http/client-common#34?

@Nyholm
Copy link
Member

Nyholm commented Aug 31, 2016

Yes, that ticket is invalid. But we still need to be clear with the plugins. Ie increase the docs.

@sagikazarmark
Copy link
Member

Okay, so based on @joelwurtz's comment, we only have to merge this, tag this and update the version number in client common (this is only a problem with plugins, right?)

@sagikazarmark
Copy link
Member

Clients themselves are okay, right?

@Nyholm
Copy link
Member

Nyholm commented Aug 31, 2016

See my previous comment: #116 (comment)

I'll make sure to do some PRs tomorrow if nobody beats me to it

@joelwurtz
Copy link
Member Author

joelwurtz commented Aug 31, 2016

In php-http/client-common#42

  • PluginClient
  • HttpAsyncClientEmulator
  • Doc block in Plugin
  • Most of our test code

All async client are already good

Need to do :

  • CachePlugin
  • Integration tests

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.

4 participants