namshi / cuzzle Goto Github PK
View Code? Open in Web Editor NEWThis library let's you dump a Guzzle request to a cURL command for debug and log purpose.
Home Page: https://github.com/namshi/cuzzle
This library let's you dump a Guzzle request to a cURL command for debug and log purpose.
Home Page: https://github.com/namshi/cuzzle
Hi,
I'm doing a request with one text field (named JSON) and two files (named file and icon).
This is the log output:
curl 'http://test.local/app_dev.php/test/post' \ -A 'Guzzle/5.3.0 curl/7.22.0 PHP/5.5.27-1+deb.sury.org~precise+1' \ -H 'Content-Type: multipart/form-data' -X POST \ -d '--55af920568ab9 Content-Disposition: form-data; name="JSON" {"title":"Title","filename":"video.mp4","startdate":"22-07-2015","starttime":"02:49","enddate":"31-12-2016","endtime":"23:59","https":"yes"} --55af920568ab9 Content-Disposition: form-data; name="icon"; filename="fok_original.jpg" Content-Type: image/jpeg '
I added a var_dump on controller and $request->request->all() shows me the JSON field and $request->files has two elements, file and icon.
Anyone can replicate this?
Thank you.
I think it's closely related to the other two issues: #1 and #9.
When I send Guzzle request with PUT method with the binary data, I get the following exception.
FatalErrorException in CurlFormatter.php line 135:
Error: escapeshellarg(): Input string contains NULL bytes
FYI, I leave a part of the stack trace. I don't think you need all of them.
in CurlFormatter.php line 135
at escapeshellarg() in CurlFormatter.php line 135
at CurlFormatter->extractBodyArgument() in CurlFormatter.php line 218
at CurlFormatter->extractArguments() in CurlFormatter.php line 54
at CurlFormatter->format() in GuzzleCollector.php line 99
at GuzzleCollector->collect() in Profiler.php line 223
...
I already saw the pull request #17. But I don't think it's a good idea to show binary data. Instead, I suggest you to put them into a file and give curl argument with -d @[filename]
if the file is binary.
In CurlFormatter::extractUrlArgument
, calling withFragment
with null
throws an exception because the PSR-7 Uri implementation of Guzzle immediatly calls filterQueryAndFragment
which checks if the fragment is a string :
// CurlFormatter.php
$uri = $request->getUri();
$uri = $uri->withFragment(null); /// <----------------
$this->addCommandPart(escapeshellarg((string)$uri));
// Uri.php
public function withFragment($fragment)
{
$fragment = $this->filterQueryAndFragment($fragment); /// <----------------
if ($this->fragment === $fragment) {
return $this;
}
$new = clone $this;
$new->fragment = $fragment;
return $new;
}
private function filterQueryAndFragment($str)
{
if (!is_string($str)) { /// <----------------
throw new \InvalidArgumentException('Query and fragment must be a string');
}
return preg_replace_callback(
'/(?:[^' . self::$charUnreserved . self::$charSubDelims . '%:@\/\?]++|%(?![A-Fa-f0-9]{2}))/',
[$this, 'rawurlencodeMatchZero'],
$str
);
}
Should an empty string be passed instead ? Or not be called at all (depending if the string representation of the Uri holds the fragment, as it's the case for Guzzle) ?
Brice
CURL proxies that are passed to Guzzle are not dumped by the middleware.
Hi,
Have you planned to support Guzzle 6.x ?
Looking at Guzzle Upgrade Guide, lot of things have changed.
Any idea of time required ?
Thanks,
Regards
I've got this error after upload big file (~10MB video) via Guzzle:
FatalErrorException in CurlFormatter.php line 137:
Error: escapeshellarg(): Argument exceeds the allowed length of 2097152 bytes
Traceback:
1. in CurlFormatter.php line 137
2. at escapeshellarg() in CurlFormatter.php line 137
3. at CurlFormatter->extractBodyArgument() in CurlFormatter.php line 220
4. at CurlFormatter->extractArguments() in CurlFormatter.php line 54
5. at CurlFormatter->format() in GuzzleCollector.php line 100
6. at GuzzleCollector->collect() in Profiler.php line 218
7. at Profiler->collect() in ProfilerListener.php line 128
8. at ProfilerListener->onKernelResponse() in WrappedListener.php line 61
HAR, or cURL == > Guzzle request ?
Cuzzle formats correctly headers when they are passed to the Request object, but not when passed to the array options of Guzzle. These two pieces of code should return the same value, but they don't.
<?php
use Namshi\Cuzzle\Formatter\CurlFormatter;
use GuzzleHttp\Psr7\Request;
require_once(__DIR__.'/vendor/autoload.php');
// curl 'http://some-url.com/path' -H 'Some-Header: lorem'
echo (new CurlFormatter())->format(
new Request('get', 'http://some-url.com/path', ['Some-Header' => 'lorem']),
[]
);
// curl 'http://some-url.com/path'
echo (new CurlFormatter())->format(
new Request('get', 'http://some-url.com/path'),
['headers' => ['Some-Header' => 'lorem']]
);
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.