-
Notifications
You must be signed in to change notification settings - Fork 60
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
Decouple from HTTP client library #173
Conversation
0da2378
to
0739cc4
Compare
@@ -195,6 +195,9 @@ implements ``\Psr\Log\LoggerInterface``. For instance, when using Monolog_:: | |||
Then add the logger as a subscriber to the cache invalidator:: | |||
|
|||
use FOS\HttpCache\EventListener\LogSubscriber; | |||
use FOS\HttpCache\CacheInvalidator; | |||
|
|||
$invalidator = new CacheInvalidator( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incomplete
interesting. kind of sounds like the client abstraction should be a PSR that builds on top of PSR-7... but i guess for now we have to live with that. i am not so sure if this is still a 1.x thing or we should bump to 2.0 for this. looks like a couple of protected methods severly change behaviour. |
Yeah, I tried to limit BC issues by falling back to our current Guzzle 3 implementation, but it’s undoable to have no breaks at all. I’m okay with postponing this to 2.0, but would like to finish this PR up shortly to get it over and done with. I’m against opening a 2.0 branch as we decided to limit parallel branches as much as possible. Do you agree with changing the branch alias to 2.0 in this PR? I think we have some things that we should finish in 1.0 first, so we could hold off merging this for a little while. |
i agree to bump the version to 2 in this and make 1.3 the last 1.x version of the bundle. we should withhold from tagging 2.0.0 for a bit after merging this however, to give it time to settle and give us some time for more bc breaks if needed. about the whole http client abstraction layer: i wonder if it would be worth to move that to its own repository. then again, that will explode the complexity of the abstraction, as now we only need to provide the minimum we need to operate. |
There is already several such libraries: https://packagist.org/search/?q=http-adapter (and probably others with different names) And given that PSR-7 is close, I think the best solution is probably to expect client with a single method |
thanks @stof, indeed a lot of choice. the egolen / ivory one looks quite good at first glance. is that a good choice, or do you have any recommendations which one to pick? and any idea how risky it is to implement PSR7 right now? if the interface changes before its finally accepted, we would become incompatible. and do you mean to write a wrapper around that wrapper? ivory seems to provide a sendRequest method that accepts a PSR request object... |
https://github.com/saxulum/saxulum-http-client-interface another suggestion that came through twitter |
Yes, let’s use one of the already existing HTTP adapters; it makes no sense to reinvent the wheel. I like ivory-http-adapter as it’s compatible with PSR-7 and has parallel requests, which we need. We do require some extra functionality on top of pure HTTP messages:
I guess I could make InvalidationRequest extend PSR’s RequestInterface to offer this functionality. |
that sounds like a good plan to me. |
9a1f1dd
to
d87dd9d
Compare
Okay, switched to the egloen/http-adapter for HTTP library abstraction. Unfortunately, that lib relies on phly/http for its PSR-7 implementation, and phly/http does not allow PURGE as a HTTP method (which makes sense in a way, as PURGE is not proper HTTP, but still). I’m still looking for a way to work around this. |
looks good! voting for PSR-7 went into another iteration (though about documentation rather than code as far as i understood). i think we best not release any 2.0 version before it is final and we can rely on the official interfaces. lets hope this will happen within the next month or two. |
Yes, let’s wait for PSR-7. While working on this PR, egeloen/http-adapter has changed its API multiple times. I hope that with PSR-7 the dust will settle and both HTTP adapters and message library (phly/http) become stable enough to use them here. |
Update: ivory-http-adapter has been split into multiple packages and moved to a separate organisation: php-http. |
"repositories": [ | ||
{ | ||
"type": "vcs", | ||
"url": "https://github.com/ddeboer/guzzle6-adapter" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be removed when the adapter has been merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is now.
|
||
public function getAllowedSchemes() | ||
{ | ||
return array('http'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is different for Nginx and Varnish, this should probably be moved back into the Varnish and Nginx client classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah lets make this method abstract here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah sorry. no, lets move it to the clients.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering: does getAllowedSchemes()
actually make sense? Nginx and Symfony already allow both HTTP and HTTPS. What about Varnish? If you have a SSL terminator in front of Varnish (such as Nginx or Pound), couldn’t you also send invalidation requests to https://your-app.com
(I may be mistaken here)? So shouldn’t we always allow both HTTP and HTTPS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And related to this, should we perhaps remove the scheme guessing (from getDefaultScheme()
) when setting a baseUrl as well?
- It’s more explicit than what we have now.
- Consequence: users need to always set
http://fos.lo
instead offos.lo
(http://fos.lo:123
instead offos.lo:123
). But the latter isn’t a valid URI anyway, so it’s weird to be able to pass it to a method calledsetBaseUrl()
. We can see our confusion in the method’s docblock:Set application hostname, optionally including a base URL
. Therefore removing the scheme guessing also removes this confusion.
The reason we did add the guessing was convenience for users, if I recall correctly. This may still be the case for proxy servers (e.g. Varnish at 127.0.0.1:456
), but at least for the base URIs I think the convenience is outweighed by the confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, when sending invalidation requests, it is not the baseUrl’s scheme that is used, but that of the configured $servers
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, lets just make protocol required and not guess neither validate it. most likely varnish invalidation should go directly to varnish and not via the ssl terminator, but if somebody really needs that i don't see why we should forbid it.
2.0.0 (unreleased) | ||
------------------ | ||
|
||
* Decoupled from the Guzzle HTTP client. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could say what we use instead.
read through all of it again and added quite a few comments - sorry about that. but its mostly details or things not directly related to the PR. i propose to move most of them into issues so we can merge this soon - its getting big this PR. |
@dbu No problem. On the contrary, thanks for the thorough review. 😄 |
if ($response->getStatusCode() >= 400 | ||
&& $response->getStatusCode() < 600 | ||
) { | ||
$exceptions[] = ProxyResponseException::proxyResponse($response); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now throwing exceptions again for responses with error status codes. Unfortunately, I see no easy way to get the corresponding request. Although Guzzle should return responses in the same order as the requests, things get difficult when the responses are mixed with exceptions (for timeout errors).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well thats already a lot better.
there was a test failure. apart from that i am fine with squash and merge if you want. won't be much online the next days so go ahead if you want. |
Remove custom adapters Update to PSR-7, Guzzle 6 and php-http/adapter Remove PHP 5.3 from build matrix Adopt changes in http-adapter and use discovery Remove dependencies on Guzzle (components) We use Guzzle 6 for testing, so it needs to stay in require-dev. Use php-http/message-decorator Change branch alias to 2.0.x Add docs Allow failures on hhvm Fix connection timing issues Remove all Guzzle-specifics from the tests, too Change documentation links to stable Try to run HHVM on Guzzle 5 Remove Bash file Add version notice to docs Fix setPurgeLocation docs Don't mock exceptions * It’s easier not to * Mocking exceptions causes HHVM to fail with "Call to a member function mockery_getName() on a non-object (NULL)" Extract createUri() method Remove allow_failures for HHVM Add response code to cache hit/miss assertion message Throw exceptions for error status codes
I realize this PR was merged quite some time ago, but I have a question
Did you open an issue on varnish project regarding this? I experienced the same problem with v1.4 and came up with the following workaround in varnish.vcl instead of using a
I anyway don' know why you don't use obj.hits in order to detect a HIT or not as virtually everybody else do that, AFAIK |
the obj.hits worked well with varnish 3. varnish 4 seems not to set obj.hits reliable anymore, see for example: https://coderwall.com/p/zksgmq/vanish-4-effectively-detect-hit-miss-in-vcl if this was ammended in later versions of varnish 4, do you have some source about that? if we can avoid the sleep in favor of something more reliable, we would prefer that as well. |
I am using varnish 4.0.3 and have never experienced any issues with obj.hits. |
The change in That would allow us to revert the changes we made in our VCLs (and docs) for 4.0. @vidarl Do you have time to experiment with changing the VCLs and running the FOSHttpCache tests to see if you get the same results for hits/misses? |
Fix #53.
Goals:
Todo: