-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Profiler] Add HttpClient copy as curl feature #37691
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
{% extends '@WebProfiler/Profiler/layout.html.twig' %} | ||
|
||
{% import _self as helper %} | ||
|
||
{% block toolbar %} | ||
{% if collector.requestCount %} | ||
{% set icon %} | ||
|
@@ -88,6 +90,7 @@ | |
{% if trace.options is not empty %} | ||
{{ profiler_dump(trace.options, maxDepth=1) }} | ||
{% endif %} | ||
<button class="btn btn-sm" data-clipboard-text="{{ helper.render_curl(trace) }}">Copy-as-Curl</button> | ||
</th> | ||
{% if profiler_token and profiler_link %} | ||
<th> | ||
|
@@ -121,11 +124,28 @@ | |
</tr> | ||
</tbody> | ||
</table> | ||
{# tmp: introspect the "trace" #} | ||
{{ dump(trace) }} | ||
{% endfor %} | ||
{% endif %} | ||
</div> | ||
</div> | ||
{% endfor %} | ||
{% endif %} | ||
</div> | ||
|
||
<script type="text/javascript">//<![CDATA[ | ||
|
||
document.querySelectorAll('[data-clipboard-text]').forEach(function(button) { | ||
button.addEventListener('click', function() { | ||
navigator.clipboard.writeText(button.getAttribute('data-clipboard-text')); | ||
}) | ||
}); | ||
|
||
//]]></script> | ||
|
||
{% endblock %} | ||
|
||
{% macro render_curl(trace) %} | ||
curl "{{ trace.url }}" --compressed -H "Connection: keep-alive" -v | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we can provide a reusable service (request to curl) that be neat :) i believe there are some CurlBuilders in the wild to take inspiration from. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, I would say that it must at least include the method and the headers. For the body, that's harder. Also, be careful about the fact that you need to escape There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
would there be any reason to not make it a first class feature, if we want this feature for the profiler? a usecase i have in mind is adding the curl command in some log entries its context. Or perhaps display in CLI verbose mode. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, if you want to make it a first-class feature, the argument of this API cannot be the internal data structure of this collector There was a problem hiding this comment. AAC3 div>Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it will be easier in the datacollector, agreed i'll move this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a ref, the curl formatter used by httplug: https://github.com/php-http/message/blob/master/src/Formatter/CurlCommandFormatter.php There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'll check this thx |
||
{% endmacro %} |
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.
instead of writing support for
Copy to clipboard
as an inline script in this panel, I suggest adding such a feature in the shared JS of the profiler pages, so that it can be reused by any other panel too (as we do for tabs and toggles).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'll refactor indeed