-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpClient][WebProfilerBundle] Add button to copy a request as a cURL command #43931
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
[HttpClient][WebProfilerBundle] Add button to copy a request as a cURL command #43931
Conversation
Hey! To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done? Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review. Cheers! Carsonbot |
The WebProfiler pages are targetting modern browsers only. And all modern browsers support it |
src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php
Outdated
Show resolved
Hide resolved
8e80365
to
4ba28ab
Compare
@stof @nicolas-grekas I'm not really sure of how I should handle the body in the generated |
@Deuchnord for such cases, I would suggest skipping the "copy as curl" button |
src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php
Outdated
Show resolved
Hide resolved
c2e3fff
to
d09175a
Compare
b2fafdd
to
0a3b52e
Compare
0a3b52e
to
34ef21e
Compare
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.
I'm not sure the current logic works when there are redirects involved.
Can you add a test case that hits http://symfony.com/releases.json
to trigger one?
The curl command-line should only contain the first call of course.
src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php
Outdated
Show resolved
Hide resolved
Looks like |
812cb6c
to
0b76a18
Compare
indeed, but why don't we use |
Because I didn't spot it until now, thanks for pointing it 😅 |
There's a failure on appveyor :) |
I'm not sure to understand the error given by the tests on AppVeyor:
If I read the config file correctly, the |
openssl is first disabled then re-enabled, to ensure that the test suite doesn't rely on implicit deps, including ext-openssl. |
71e4d65
to
d7adc1f
Compare
d7adc1f
to
67c9146
Compare
Thank you @Deuchnord. |
can we collect class request objects and use https://github.com/php-http/message/blob/master/src/Formatter/CurlCommandFormatter.php for it? it can make service usable and universal |
There is no class request object in symfony/http-client |
… body for c… (Phillip Look) This PR was merged into the 6.1 branch. Discussion ---------- [HttpClient][WebProfilerBundle] Catch errors when encoding body for c… | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | In Symfony 6.1 a [button to copy a request as a cURL command](#43931) was introduced for the profiler. But if I post a binary file containing null characters using the curl-http-client the `HttpClientDataCollector` throws an error. ``` Warning: Uncaught ValueError: escapeshellarg(): Argument #1 ($arg) must not contain any null bytes ``` My solution is to catch the `ValueError` in this situation and to return `null` as the resulting curl command. Returning `null` seems to be the standard handling for unexpectad values in this data collector. Commits ------- 36e6fa0 [HttpClient][WebProfilerBundle] Catch errors when encoding body for curl command line
… body for c… (Phillip Look) This PR was merged into the 6.1 branch. Discussion ---------- [HttpClient][WebProfilerBundle] Catch errors when encoding body for c… | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | In Symfony 6.1 a [button to copy a request as a cURL command](symfony/symfony#43931) was introduced for the profiler. But if I post a binary file containing null characters using the curl-http-client the `HttpClientDataCollector` throws an error. ``` Warning: Uncaught ValueError: escapeshellarg(): Argument #1 ($arg) must not contain any null bytes ``` My solution is to catch the `ValueError` in this situation and to return `null` as the resulting curl command. Returning `null` seems to be the standard handling for unexpectad values in this data collector. Commits ------- 36e6fa0935 [HttpClient][WebProfilerBundle] Catch errors when encoding body for curl command line
… body for c… (Phillip Look) This PR was merged into the 6.1 branch. Discussion ---------- [HttpClient][WebProfilerBundle] Catch errors when encoding body for c… | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | In Symfony 6.1 a [button to copy a request as a cURL command](symfony/symfony#43931) was introduced for the profiler. But if I post a binary file containing null characters using the curl-http-client the `HttpClientDataCollector` throws an error. ``` Warning: Uncaught ValueError: escapeshellarg(): Argument #1 ($arg) must not contain any null bytes ``` My solution is to catch the `ValueError` in this situation and to return `null` as the resulting curl command. Returning `null` seems to be the standard handling for unexpectad values in this data collector. Commits ------- 36e6fa0935 [HttpClient][WebProfilerBundle] Catch errors when encoding body for curl command line
Adding a button to each request in the HttpClient section to copy it as a
curl
command that can be then pasted either in the terminal (on Linux and Mac) or in an application that can parse it (like Insomnia).Work in progress:
curl
command