guzzle / guzzle Goto Github PK
View Code? Open in Web Editor NEWGuzzle, an extensible PHP HTTP client
Home Page: https://docs.guzzlephp.org/
License: MIT License
Guzzle, an extensible PHP HTTP client
Home Page: https://docs.guzzlephp.org/
License: MIT License
Guzzle does not ship with it's dependencies.
PHP Fatal error: Class 'Symfony\Component\EventDispatcher\EventDispatcher' not found in /var/www/Public/library/Vendors/Guzzle/src/Guzzle/Common/AbstractHasDispatcher.php on line 42
Is it possible for you to git submodule the dependencies for those who don't want to use Phar?
I'm submitting a form with a picture. Using a browser I get this:
Content-Disposition: form-data; name="picture"; filename="thepicture.jpg"
Content-Type: image/jpeg
But using guzzle I get this:
Content-Disposition: form-data; name="picture"; filename="C:\Windows\Temp\uplC14D.tmp"
Content-Type: application/octet-stream
Any bug here?
Guzzle makes use of many factory classes and methods, which I like. The only problem I have is that they do not support late static binding. For example, if I extend the ServiceBuilder
class like so
<?php
namespace Foo;
use Guzzle\Service\ServiceBuilder;
class FooBuilder extends ServiceBuilder { /* ... */ }
When I do FooBuilder::factory( /* ... */ )
, I do not get an instance of Foo\FooBuilder
, I get an instance of Guzzle\Service\ServiceBuilder
. The only way to change that is to overwrite the factory
method, which is not a great I idea since it contains a great deal of logic.
So, in your factory methods and classes, if you change your return new self( /* ... */ )
statements into new return new static( /* ... */ )
, that would make me ecstatic!
Is there a way to add a Plugin to all clients getting from service builder.
My use case i build a data collector for GuzzlebBundle (Symfony2) the problem is that i must now add my plugin to all clients. So the user use the $this->get('guzzle.service_builder')->get('myClient')
to get the client. Is there a simple way or should i must extends the service builder class with my own and extends the get
method
i get this message the headers and the body is Array
so here is a var_export missing
guzzle v2.5.0
{{{
[response] HTTP/1.1 400 Bad Request
Date: Thu, 31 May 2012 20:12:52 GMT
Server: Apache
Cache-Control: public, max-age=600
Expires: Thu, 31 May 2012 20:22:52 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: POST,GET,PUT,DELETE,HEAD
Access-Control-Max-Age: 604800
Content-Length: 171
Connection: close
Content-Type: application/json; charset=utf-8
{"errors":[{"message":"Unable to retrieve server info [500]:\nHeaders: Array\n(\n)\nBody: Array\n(\n [error] => couldn't connect to host [7]\n)\n","name":500,"at":""}]} [] []
}}}
Add a history HTTP plugin that can be used to track all requests issued through the plugin.
The same request parameter name can appear more than once in an http query string - but the processing of the request string means that all but the last occurrence are lost.
Example:
$client = new \Guzzle\Http\Client();
$request = $client->get("http://example.com/search?q=blah&facet=class&facet=property");
will result in a request like this being sent:
http://example.com/search?q=blah&facet=property
but should be:
http://example.com/search?q=blah&facet=class&facet=property
Instead of handling mock responses only in tests, create a new queued mock response plugin that can be attached to HTTP request and clients.
http://tools.ietf.org/html/draft-gregorio-uritemplate-08
Would like support for URI templates in requests sent through a client and in service descriptions.
When response object is created constructor validates response code against hardcoded list:
Guzzle\Http\Message\Response
public function __construct($statusCode, $headers = null, $body = null)
{
if (!array_key_exists($statusCode, self::$statusTexts)) {
throw new BadResponseException(
'Invalid response code: ' . $statusCode
);
}
...
and if the code is not in the list a BadResponseException is thrown.
This means that there is no way to use custom codes (like in our case), not even to mention that the list is far from the full list of available standard codes.
I see the intention of this list: to provide proper translation mechanism for the codes, however it should not be used for validation, especially when these is no easy way around it.
In the case where a user supplied URL (or pastebin/etc) is posted to, with user supplied contents you could land up sending private files.
$_POST = array('firstname' => '@/etc/passwd');
$request = $client->post('http://www.abcd.net/callback', null, array (
'firstname' => $_POST['firstname']
));
I have downloaded guzzle.phar from official website and created simple script:
require 'guzzle.phar';```
I get:
Warning: require_once(phar://D:\htdocs\guzzle.phar\vendor\symfony\class-loader\Symfony\Component\ClassLoader\UniversalClassLoader.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: phar error: "vendor/symfony/class-loader/Symfony/Component/ClassLoader/UniversalClassLoader.php" is not a file in phar "D:/htdocs/guzzle.phar" in D:\htdocs\guzzle.phar on line 14
I have PHP 5.3.9 with enabled PHAR extension (Windows x64).
The test webserver is currently only implemented in node.js. Create a PHP implementation with instructions that can be run using a different web server (apache, nginx, php-cli, etc). Create an interface and PHPUnit configs for instantiating different test webservers.
It's not possible to set own default HTTP headers. You can try use:
$client->getConfig()->set('curl.CURLOPT_HTTPHEADER',array('Expect:'));
Unfortunately, it will replace all headers set before (for example Cookie headers set by CookiePlugin):
You can fix it for example merging arrays with headers. Or more flexible way, something like $client->setParam('defaultHeaders',array());
You should add something to Guzzle in Guzzle\Service\Client
like this...
class Client // extends ...
{
// ...
public function __call($method, $args)
{
$command = $this->getCommand($method, $args);
return $this->execute($command);
}
// ...
}
That way, in addition to calling commands like...
$command = $s3->getCommand('get_object');
$command->setBucket('test');
$command->setObject('foo');
$result = $s3->execute($command);
...you could also do this...
$result = $s3->getObject(array(
'bucket' => 'test',
'object' => 'foo',
));
...which I think a lot of people would like.
(Sorry if I have some of the syntax wrong.)
Feature request: When making a request with the Guzzle\Http\Request object I need the ability to set/get a raw body/query (as a string). Currently (if I understand correctly) it must be a Guzzle\Common\Collection object with key/val pairing.
This is needed (for example) when making a request to many Google APIs. Currently I'm (without Guzzle, want to switch) doing a cURL request setting CURLOPT_POSTFIELDS to a raw json string.
A breaking change was made to composer: http://nelm.io/blog/2012/02/an-update-on-composer/
The Guzzle composer.json file needs to be updated so that builds start working again.
I am trying to add support for HTTP 429 responses to a web service client I am developing. Specifically, I was attempting to specify my own callable $failureCodes function and checking for the header presence in the response.
However, the problem I ran into is that I have no way to handle this with the current implementation of the ExponentialBackoffPlugin. With the current design there is no way for the "should we retry" callback to "tell" the "calculateWait" callback how long to delay. The calculateWait callback can't determine that for itself either since it doesn't have access to the Response object.
The two options I see:
I don't have a problem implementing either: the latter is much simpler, but the former seems like it may be a more robust approach (less client code, and potentially useful to many) albeit greater in scope. Please let me know your thoughts.
Are the service definitions being cached when executing dynamic commands based on a XML definition file (for example)?
Regards,
Christian.
For the Symfony2 Bundle https://github.com/ddeboer/GuzzleBundle i wan't add two adapters one for monolog and one for the datacollector. It would be nice when i can attach multiple adapters to the LogPlugin.
The documentation talks about filter attribute instead of filters in the PHP code.
Exemple in guzzlephp.org/guide/service/creating_dynamic_commands.html
filter CSV list of functions or static functions that modifies a string @guzzle key filter="strtoupper,strrev"
Hi,
you should check if cURL is installed and well configured here: https://github.com/guzzle/guzzle/blob/master/src/Guzzle/Guzzle.php#L67.
The best way should be to throw an exception and/or to fallback on another HTTP client.
Cheers,
william
I installed guzzle from packagist.org by simply creating a dependency in my project's composer.json (the main reason you're not seeing pull requests from me -- so far). Since the vendor/Doctrine
, vendor/Monolog
, and vendor/Symfony/Component/ClassLoader
folders were empty, It looks like there are some missing dependencies:
"require": {
"php" : ">=5.3.2",
"doctrine/common" : "2.1.*",
"monolog/monolog" : "1.0.*",
"symfony/class-loader": "2.0.*"
},
symfony/class-loader
may not be configured correctly (not sure by whom) since it loads in
`````` vendor/guzzle/guzzle/vendor/Symfony/class-loader/Symfony/Component/ClassLoaderrather than
vendor/guzzle/guzzle/vendor/Symfony/Component/ClassLoader```
but things seem to be working ok.
You should probably add a changelog listing the BC breaks. Or does it already exist somewhere?
We're using an API that provides 422 responses for well-formed and understood requests that cannot be completed due to other errors (e.g. duplicate entry). Is it possible to add this to the $statusTexts array.
i've added it locally as 422 => 'Unprocessable Entity',
The ServiceBuilder
uses the magic __sleep()
method for serializing, but the ArrayCookieJar
uses the Serializable
interface. You should probably switch the ServiceBuilder
to using the Serializable
as well.
Request parameter names can legally contain dots - but they get converted to underscores by the query string processing.
Example:
$client = new \Guzzle\Http\Client();
$request = $client->get("http://example.com/search?q=blah&facet.field=class");
will actually send a request like this:
GET http://example.com/search?q=blah&facet_field=class
where "facet_field" should be "facet.field".
The problem may be caused by the use of the "parse_str" function in Url.php, which will convert spaces and dots into underscores.
...doesn't appear to be in the distributed src. It's referenced in:
// src/Guzzle/Service/Client.php
17 use Guzzle\Http\Curl\CurlConstants;
Not sure if this is really a problem or not, but thought I'd point it out.
As pointed out by ddeboer, A notice is thrown in Guzzle\Http\Message\AbstractMessage when multiple cache control headers are present in a response. This method must check if there are multiple cache control headers (Guzzle stores the header value as an array when duplicate headers are encountered in a response).
On http://guzzlephp.org/guide/service/service_descriptions.html it states a parameter can be configured as follows:
<param name="data" type="type:array" filters="json_encode" location="body" />
However, this throws a Guzzle\Service\Exception\ValidationException with the message "Validation errors: data: Value must be of type array". Digging into Guzzle\Service\Inspector::validateConstraint() it looks $value has already been converted to JSON at this point.
This happens for me on the v2.6.2 tag and on the master branch.
$request->addPostFields(array(
'foo'=>'bar',
'nested'=>array(
'bla'=>0,
'oh'=>1
)
));
Excepted query: foo=bar&nested[bla]=0&nested[oh]=1
Result: foo=bar&nested[0]=1
http://www.guzzlephp.org/docs/guide/http/caching/
The caching plugin does a whole lot of cool stuff. Explaining caching and how to best leverage the caching plugin would be very helpful.
Could you please improve the contrast in the code samples on http://www.guzzlephp.org/?
I am having a very hard time reading it because the colors are nearly identical :(
Please can you change the visibility to protected
https://github.com/guzzle/guzzle/blob/master/src/Guzzle/Http/Plugin/LogPlugin.php#L180
so i can extends this plugin and override the function
I suggest to change the base install dir IN PEAR package.xml, so the command pear install guzzle/guzzle install in PEAR_PATH/Guzzle and not in PEAR_PATH/guzzle/Guzzle because sf2 UniversalClassAutoloader (2.0.10) can't find the Guzzle Namespaces when you set
$loader->registerNamespaceFallbacks(explode(':'), get_include_path());
Consider example:
$request=$this->post('http://example.com');
$request->addPostFields(array(
'a'=>array('b'=>'c')
));```
Result:
Notice: Undefined offset: 0 in D:\library\Guzzle\Http\Message\EntityEnclosingRequest.php on line 130
You need to use "hack":
```<?php
$request=$this->post('http://example.com');
$request->setBody(http_build_query(array(
'a'=>array('b'=>'c')
)));```
Why you didn't use [http_build_query](http://php.net/manual/en/function.http-build-query.php) in Guzzle\Http\QueryString to generate query?
It would be nice if Guzzle supported sending requests through a proxy like Zend Http Client:
See Zend Http Client's "proxy adapter" here:
https://github.com/zendframework/zf2/blob/master/library/Zend/Http/Client/Adapter/Proxy.php
(Guzzle was brought to my attention via the recent merge of guzzle into the goutte library)
Investigate the possibility of a command line tool that would read service descriptions and generate snippets of code that could be added to a client. For example:
<command name="get_comment" method="GET" path="/comments/{{id}}">
<doc>Get a comment by ID</doc>
<param name="id" type="string" required="true" location="path" doc="Comment ID" />
</command>
Would be translated to:
<?php
/**
* Get a comment by ID
*
* @param string $id Comment ID
*
* @return Response|DynamicCommand
*/
public function getComment($id)
{
$command = $this->getCommand('get_comment', array(
'id' => $id
));
return $this->getConfig('client.sync') ? $this->execute($command) : $command;
}
The above code could then be added to a client class to make it easier to use the web service. Would be nice to be able to specify whether command parameters are expanded into separate arguments or if an array should be used as an argument for commands with many parameters.
Loading the phar with "require_once 'guzzle.phar'" fails:
[Tue Feb 28 08:57:33 2012] [error] [client 127.0.0.1] PHP Warning: require_once(phar://Guzzle/vendor/symfony/class-loader/Symfony/Component/ClassLoader/UniversalClassLoader.php): failed to open stream: phar error: "vendor/symfony/class-loader/Symfony/Component/ClassLoader/UniversalClassLoader.php" is not a file in phar "Guzzle" in /home/jzh/git/kasabi-api/lib/guzzle/guzzle.phar on line 3
I think this may be the same as issue #19, but I've got the latest phar (as at 09:00 on 28th Feb 2012 UTC), and I see the same problem..
I'm on Ubuntu 11.10, with PHP 5.3.6 with phar enabled.
The top of the phar contains this (which looks like the updated version from issue #19):
require_once 'phar://Guzzle/vendor/symfony/class-loader/Symfony/Component/ClassLoader/UniversalClassLoader.php';
$classLoader = new Symfony\Component\ClassLoader\UniversalClassLoader();
$classLoader->registerNamespaces(array(
'Guzzle' => 'phar://Guzzle/src',
'Symfony\Component\Validator' => 'phar://Guzzle/vendor/symfony/validator',
'Symfony\Component\EventDispatcher' => 'phar://Guzzle/vendor/symfony/event-dispatcher',
'Doctrine' => 'phar://Guzzle/vendor/doctrine/common/lib',
'Monolog' => 'phar://Guzzle/vendor/monolog/monolog/src'
));
$classLoader->register();
Is there something else that I'm missing?
Cheers, Julian.
I'm creating this issue because I'm being ignored in
Guzzle3/guzzle-silex-extension#3
Please update the provider ...
From abstract ClientInterface.php:
/**
* Create a GET request for the client
*
* @param string $path (optional) Resource URI of the request. Use an
* absolute path to override the base path, or a relative path to append
* @param array|Collection $headers (optional) HTTP headers
* @param string|resource|array|EntityBody $body (optional) Where to store
* the response entity body
*
* @return RequestInterface
*/
function get($uri = null, $inject = null);
Note that $body is documented, but missing from method
but it's used in the implementation in Client.php
public final function get($path = null, $headers = null, $body = null)
{
return $this->createRequest('GET', $path, $headers, $body);
}
I've got the notice below, after upgrading Goutte.
Notice - Uninitialized string offset: 0 in phar://APPPATH/vendor/Goutte/goutte.phar/vendor/guzzle/guzzle/src/Guzzle/Http/Message/EntityEnclosingRequest.php on line 132
Is this a bug or I do somthing wrong?
Thanks.
So in the refactoring of cookies (2.6.4 -> 2.6.5). The key for the cookie header changed from "Cookie" to "cookie". I know headers should technically be case insensitive. But for one of my scripts running guzzle broke cause they seem to care about the case of the header key.
The rest of the headers sent by guzzle seem to be Cap-Words.
Think changing the header key back from "cookie" to "Cookie" makes sense?
Do you guys consider this a bug or should I find a workaround?
Running phing -f build/build.xml template will generate a project skeleton. The build script should rename Client.php or Client-Xml.php to the name entered by the user.
Check out discussions below:
http://stackoverflow.com/questions/6244578/curl-post-file-behind-a-proxy-returns-error
http://the-stickman.com/web-development/php-and-curl-disabling-100-continue-header/
http://matthom.com/archive/2008/12/29/php-curl-disable-100-continue-expectation
The problem is in Guzzle\Http\Message\EntityEnclosingRequest line 32
$this->setHeader('Expect', '100-Continue');
There should be possibility disabling it as it causes a lot of problems.
To debug, check curl verbose log - it shouldn't send Expect:100-Continue when request is POST.
http://www.guzzlephp.org/docs/guide/http/creating_plugins/ needs to be written to help explain the plugin system.
Consider example:
useful discussion: https://bugs.php.net/bug.php?id=49571
It seems that if I try to post a request without any body, I am getting a 411 error of length required. If it cannot determine the length of the request body, it should set the content length to 0. When I manually set that header, it resolved my issue.
When submitting a form with file fields, empty file fields must be submitted too.
See a possible solution here: http://stackoverflow.com/a/6367949
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.