Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[DX][WebProfilerBundle] Add Pretty Print functionality for Request Content#28919
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
[DX][WebProfilerBundle] Add Pretty Print functionality for Request Content#28919
Uh oh!
There was an error while loading.Please reload this page.
Conversation
javiereguiluz commentedOct 19, 2018
I like this proposal a lot. I would apply this behaviour by default, without any button or toggle. To prevent issues with complex queries, I'd apply a |
ro0NL commentedOct 19, 2018
I think it should be pretty by default, but a |
stof commentedOct 19, 2018
and if we want to do it all the time (with a tab switcher to view the raw one), it would make sense to do the pretty-printing server-side. |
SamFleming commentedOct 19, 2018
👍 Sounds good. I'll look at getting that implemented. If we're doing the pretty-printing on the server, that would mean we're putting the entire payload into the DOM twice, once "pretty-printed", the other raw – I'm assuming most payloads aren't too big so this won't be an issue - are we okay with this? |
ro0NL commentedOct 19, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
also instead of pretty JSON, wouldnt VarDumper (thus collapsible) be far more useful? |
d985841 tod56ed85CompareSamFleming commentedOct 19, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Okay, so, I've taken the above feedback, rebased and updated the UI. There are now "Pretty" and "Raw" tabs. I've left the formatting down to JS for reasons discussed later. I definitely prefer this. Thank you for the suggestions 👍
I don't have much experience with the internals of the profiler. However, from what I can workout there are a few options we have to pretty print on the server. I'm assuming the method of pretty-printing we'd use is
It would be great to hear some feedback on the above options as I'm not really sure which route to take.
I had been thinking about this. My main motivation for not using VarDumper was maintaining the ability to copy the pretty-printed output and edit it (e.g. for use inPostman). If we output using the Sidenote: I've had to create commit9cdcf0b as there appears to be a bug when nesting tabs in the profiler panels. Looks like until this PR it's never been required. Shall I split this out into a separate PR? |
stof commentedOct 22, 2018
You could add a getter on the Collector object returning the pretty-printed JSON, without the need to do it at collect time (it can be computed from the raw content at render time) |
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
d73ef2e to06361a0Comparesrc/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twigShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
ro0NL commentedNov 24, 2018
We could also add a 3rd tab: "Debug" that uses |
ro0NL left a comment
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.
depending on#28919 (comment)
SamFleming commentedNov 26, 2018
Thanks for the approval@ro0NL – I've updated the regex as suggested 👌 — It will match I'm currently trying to setup the "Debug" tab as suggested but am struggling with some unexpected errors. I'll keep trying. |
ro0NL commentedNov 26, 2018
@SamFleming perhaps better to introduce the debug tab in a new PR so we dont block/postpone this one (i was just brainfarting :)) But i definitively think it's a nice addition.
yes, i tweaked it to more generic. Now matches |
SamFleming commentedNov 26, 2018
Awesome, 👌 Anything left for me to do to get this ready for merging? |
ro0NL commentedNov 26, 2018
let's wait :) i do have one last question though; what happens if the request content is not valid JSON? Even if the content-type says so.. does it crash the panel? Will developer see the error? |
SamFleming commentedNov 26, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
ro0NL commentedNov 26, 2018
Perhaps fallback to raw content only without tabs then. I.e. the current behavior |
SamFleming commentedNov 26, 2018
Done63c0219 Is this too... horrible? |
ro0NL left a comment
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.
the !="null" check is implicit, but if the null is valid raw&pretty show the same content anyway, so it doesnt really hurt and avoids 2 tabs showing null 👍
df6deac to9446debCompare
ro0NL left a comment
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.
Explicit also fine for me 😅 t:
SamFleming commentedNov 26, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Oh... I thought I saw a comment about checking I definitely prefer, as it removes any abiquity. However, if we're going this route, is there any point checking the Content-Type for being JSON? Is it worth attempting the |
ro0NL commentedNov 26, 2018
the extra overhead might bite us as we try to parse each request content, every time. Tend to prefer the explicit check here. |
SamFleming commentedNov 26, 2018
I also wonder if it's worth caching the result of |
SamFleming commentedNov 26, 2018
👌 Fair |
ro0NL commentedNov 26, 2018
actually we dont parse during the request :D (im tired), only during display in the profiler. But yeah, i think we should be conservative, and expand as needed. |
ro0NL commentedNov 26, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
correct. We should return string|null (checking for last_error intermediary) and call it once in twig. |
SamFleming commentedNov 26, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Apologies, not quite sure what you mean here. I was thinking this91a2b39 |
ro0NL commentedNov 26, 2018
return |
ro0NL left a comment
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.
👌
SamFleming commentedFeb 13, 2019
@dunglas was there anything else you wanted me to do on this? |
fabpot commentedFeb 21, 2019
Thank you@SamFleming. |
9fcbb1e to9f85103Compare… for Request Content (SamFleming)This PR was squashed before being merged into the 4.3-dev branch (closes #28919).Discussion----------[DX][WebProfilerBundle] Add Pretty Print functionality for Request Content| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets || License | MIT| Doc PR | n/a ?## Why?Quite often when attempting to debug issues with JSON requests sent to a Symfony API, I use the Web Profiler to check the request content. More often than not the request content isn't easily readable (99% of the time it's all stuck on a single line and impossible to read). I always find myself copying + pasting the content into a random online tool to have it "pretty-print" the JSON.Usually this isn't an issue, but can be annoying when offline. There's also the security issue of sending entire JSON payloads to a third-party server just for formatting 😳. Alternatively, maybe developers copy+paste into their chosen editors and this PR is all a waste of time — I hope not 😛.## How?This PR adds "Pretty-Print" JSON functionality straight into the profiler.We can use `collector.requestheaders` to detect if the request was JSON and conditionally show the Pretty Print button.When the button is clicked, we format the JSON from the "Request Content" card.## What does it look like?Before:After:Non-JSON Requests (unchanged):## Things to consider- Is `JSON.stringify(JSON.parse(content));` the safest, most efficient way to do this?- Should the "Pretty Print" button be in-line next to the "Request Content" header? I couldn't find a pattern for this sort of thing elsewhere in the profiler.- Do people want JSON formatted with 4 spaces, would 2 spaces be preferred? Should this be a configuration option stored in localStorage (such as the light/dark theme configuration)?- Should this be a toggle? E.g. click to pretty print, then click to undo## Future ImprovementsDepending on how this is received it could be extended to support formatting different request content-types (e.g. XML formatting) — I assume.## Progress- [x] Gather feedback and decide where to perform the pretty-print: [server-side, or client-side](symfony/symfony#28919 (comment)).*It was decided server-side would be better.*Commits-------9f85103151 [DX][WebProfilerBundle] Add Pretty Print functionality for Request Content
… for Request Content (SamFleming)This PR was squashed before being merged into the 4.3-dev branch (closes #28919).Discussion----------[DX][WebProfilerBundle] Add Pretty Print functionality for Request Content| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets || License | MIT| Doc PR | n/a ?## Why?Quite often when attempting to debug issues with JSON requests sent to a Symfony API, I use the Web Profiler to check the request content. More often than not the request content isn't easily readable (99% of the time it's all stuck on a single line and impossible to read). I always find myself copying + pasting the content into a random online tool to have it "pretty-print" the JSON.Usually this isn't an issue, but can be annoying when offline. There's also the security issue of sending entire JSON payloads to a third-party server just for formatting 😳. Alternatively, maybe developers copy+paste into their chosen editors and this PR is all a waste of time — I hope not 😛.## How?This PR adds "Pretty-Print" JSON functionality straight into the profiler.We can use `collector.requestheaders` to detect if the request was JSON and conditionally show the Pretty Print button.When the button is clicked, we format the JSON from the "Request Content" card.## What does it look like?Before:After:Non-JSON Requests (unchanged):## Things to consider- Is `JSON.stringify(JSON.parse(content));` the safest, most efficient way to do this?- Should the "Pretty Print" button be in-line next to the "Request Content" header? I couldn't find a pattern for this sort of thing elsewhere in the profiler.- Do people want JSON formatted with 4 spaces, would 2 spaces be preferred? Should this be a configuration option stored in localStorage (such as the light/dark theme configuration)?- Should this be a toggle? E.g. click to pretty print, then click to undo## Future ImprovementsDepending on how this is received it could be extended to support formatting different request content-types (e.g. XML formatting) — I assume.## Progress- [x] Gather feedback and decide where to perform the pretty-print: [server-side, or client-side](symfony/symfony#28919 (comment)).*It was decided server-side would be better.*Commits-------9f85103151 [DX][WebProfilerBundle] Add Pretty Print functionality for Request Content
… for Request Content (SamFleming)This PR was squashed before being merged into the 4.3-dev branch (closes #28919).Discussion----------[DX][WebProfilerBundle] Add Pretty Print functionality for Request Content| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets || License | MIT| Doc PR | n/a ?## Why?Quite often when attempting to debug issues with JSON requests sent to a Symfony API, I use the Web Profiler to check the request content. More often than not the request content isn't easily readable (99% of the time it's all stuck on a single line and impossible to read). I always find myself copying + pasting the content into a random online tool to have it "pretty-print" the JSON.Usually this isn't an issue, but can be annoying when offline. There's also the security issue of sending entire JSON payloads to a third-party server just for formatting 😳. Alternatively, maybe developers copy+paste into their chosen editors and this PR is all a waste of time — I hope not 😛.## How?This PR adds "Pretty-Print" JSON functionality straight into the profiler.We can use `collector.requestheaders` to detect if the request was JSON and conditionally show the Pretty Print button.When the button is clicked, we format the JSON from the "Request Content" card.## What does it look like?Before:After:Non-JSON Requests (unchanged):## Things to consider- Is `JSON.stringify(JSON.parse(content));` the safest, most efficient way to do this?- Should the "Pretty Print" button be in-line next to the "Request Content" header? I couldn't find a pattern for this sort of thing elsewhere in the profiler.- Do people want JSON formatted with 4 spaces, would 2 spaces be preferred? Should this be a configuration option stored in localStorage (such as the light/dark theme configuration)?- Should this be a toggle? E.g. click to pretty print, then click to undo## Future ImprovementsDepending on how this is received it could be extended to support formatting different request content-types (e.g. XML formatting) — I assume.## Progress- [x] Gather feedback and decide where to perform the pretty-print: [server-side, or client-side](symfony/symfony#28919 (comment)).*It was decided server-side would be better.*Commits-------9f85103 [DX][WebProfilerBundle] Add Pretty Print functionality for Request Content
… for Request Content (SamFleming)This PR was squashed before being merged into the 4.3-dev branch (closes#28919).Discussion----------[DX][WebProfilerBundle] Add Pretty Print functionality for Request Content| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets || License | MIT| Doc PR | n/a ?## Why?Quite often when attempting to debug issues with JSON requests sent to a Symfony API, I use the Web Profiler to check the request content. More often than not the request content isn't easily readable (99% of the time it's all stuck on a single line and impossible to read). I always find myself copying + pasting the content into a random online tool to have it "pretty-print" the JSON.Usually this isn't an issue, but can be annoying when offline. There's also the security issue of sending entire JSON payloads to a third-party server just for formatting 😳. Alternatively, maybe developers copy+paste into their chosen editors and this PR is all a waste of time — I hope not 😛.## How?This PR adds "Pretty-Print" JSON functionality straight into the profiler.We can use `collector.requestheaders` to detect if the request was JSON and conditionally show the Pretty Print button.When the button is clicked, we format the JSON from the "Request Content" card.## What does it look like?Before:After:Non-JSON Requests (unchanged):## Things to consider- Is `JSON.stringify(JSON.parse(content));` the safest, most efficient way to do this?- Should the "Pretty Print" button be in-line next to the "Request Content" header? I couldn't find a pattern for this sort of thing elsewhere in the profiler.- Do people want JSON formatted with 4 spaces, would 2 spaces be preferred? Should this be a configuration option stored in localStorage (such as the light/dark theme configuration)?- Should this be a toggle? E.g. click to pretty print, then click to undo## Future ImprovementsDepending on how this is received it could be extended to support formatting different request content-types (e.g. XML formatting) — I assume.## Progress- [x] Gather feedback and decide where to perform the pretty-print: [server-side, or client-side](#28919 (comment)).*It was decided server-side would be better.*Commits-------9f85103 [DX][WebProfilerBundle] Add Pretty Print functionality for Request Content



Uh oh!
There was an error while loading.Please reload this page.
Why?
Quite often when attempting to debug issues with JSON requests sent to a Symfony API, I use the Web Profiler to check the request content. More often than not the request content isn't easily readable (99% of the time it's all stuck on a single line and impossible to read). I always find myself copying + pasting the content into a random online tool to have it "pretty-print" the JSON.
Usually this isn't an issue, but can be annoying when offline. There's also the security issue of sending entire JSON payloads to a third-party server just for formatting 😳. Alternatively, maybe developers copy+paste into their chosen editors and this PR is all a waste of time — I hope not 😛.
How?
This PR adds "Pretty-Print" JSON functionality straight into the profiler.
We can use
collector.requestheadersto detect if the request was JSON and conditionally show the Pretty Print button.When the button is clicked, we format the JSON from the "Request Content" card.
What does it look like?
Before:

After:

Non-JSON Requests (unchanged):

Things to consider
JSON.stringify(JSON.parse(content));the safest, most efficient way to do this?Future Improvements
Depending on how this is received it could be extended to support formatting different request content-types (e.g. XML formatting) — I assume.
Progress
It was decided server-side would be better.