Skip to content

Added cURL formatter #50

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 9 commits into from
Aug 2, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Formatter/CurlCommandFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ public function formatRequest(RequestInterface $request)
$command .= sprintf(' -H \'%s: %s\'', $name, $request->getHeaderLine($name));
}

$body = $request->getBody()->__toString();
if (!empty($body)) {
$command .= sprintf(' --data \'%s\'', escapeshellarg($body));
$body = $request->getBody();
if ($body->getSize() > 0) {
if (!$body->isSeekable()) {
throw new \RuntimeException('Cannot take data from a stream that is not seekable');
Copy link
Member

Choose a reason for hiding this comment

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

Sending an exception here is horrible, i.e. some requests can randomly fail only on debugging (not on prod) in a symfony env with this formatter in the debug toolbar. Can we set a specific exception like : CannotFormatException (or something else) that we can catch in class using this formatter to not show something ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was planning to remove this code when your request cloner is merged.

Copy link
Contributor

Choose a reason for hiding this comment

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

is this handled outside? or should we just return something in the text that says there would be the body but we can't read it?

Copy link
Member Author

Choose a reason for hiding this comment

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

}
$command .= sprintf(' --data %s', escapeshellarg($body->__toString()));
Copy link
Contributor

Choose a reason for hiding this comment

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

i wonder if we should have some sort of sanity check to not put huge files in here? say if the body size > 5000 we truncate or just do something like [too large body] in the command? if we use this formatter eg in the symfony debug toolbar, it could break on large files

$body->rewind();
}

return $command;
Expand Down