Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
[DX][WebProfilerBundle] Add Pretty Print functionality for Request Content #28919
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
This PR adds "Pretty-Print" JSON functionality straight into the profiler.
We can use
When the button is clicked, we format the JSON from the "Request Content" card.
What does it look like?
Things to consider
Depending on how this is received it could be extended to support formatting different request content-types (e.g. XML formatting) — I assume.
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?
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 in Postman). If we output using the
I've had to create commit 9cdcf0b 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?
changed the title
[DX][WebProfilerBundle] Add Pretty Print functionality for Request Content
Oct 19, 2018
Thanks for the approval @ro0NL – I've updated the regex as suggested
I'm currently trying to setup the "Debug" tab as suggested but am struggling with some unexpected errors. I'll keep trying.
@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
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
correct. We should return string|null (checking for last_error intermediary) and call it once in twig.