content/type with Debug

is it possible to set when debuging using xdebug the content/type to application/json for example?

0
7 comments
Avatar
Vladimir Luchansky

Hello,

Sorry, didn't get it. Where do you want to set that? Please describe a use case in more details (workflow, code samples),

0

Sorry about that.

Under Run in the menu, there is Debug. I configure everything in Edit Configuration: Under PHP HTTP Request.

0
Avatar
Vladimir Luchansky

Unfortunately that's not possible.

What would be the point of it? Could you tell more details about what you'd like to achieve please?

0

To debug API requests that expect application/json without changing the code that would support the IDE default.

Is there a different way to achieve it? or my code should handle also non application/json?

0

You can use the HTTP client for that: https://www.jetbrains.com/help/phpstorm/http-client-in-product-code-editor.html
To start a debugging session, just add the XDEBUG_SESSION_START parameter, like `?XDEBUG_SESSION_START=1`.

0

So for example using content-type header as follows

<?php
header("Content-Type: application/json; charset=UTF-8");
$data = array("hello","world");
echo json_encode($data);

will still cause unintended output after intended ouput with built-in web server

["hello","world"]<script>(function() {
  var ws = new WebSocket('ws://' + window.location.host + '/jb-server-page?reloadServiceClientId=9');
  ws.onmessage = function (msg) {
      if (msg.data === 'reload') {
          window.location.reload();
      }
      if (msg.data.startsWith('update-css ')) {
          var messageId = msg.data.substring(11);
          var links = document.getElementsByTagName('link');
          for (var i = 0; i < links.length; i++) {
              var link = links[i];
              if (link.rel !== 'stylesheet') continue;
              var clonedLink = link.cloneNode(true);
              var newHref = link.href.replace(/(&|\?)jbUpdateLinksId=\d+/, "$1jbUpdateLinksId=" + messageId);
              if (newHref !== link.href) {
                clonedLink.href = newHref;
              }
              else {
                var indexOfQuest = newHref.indexOf('?');
                if (indexOfQuest >= 0) {
                  // to support ?foo#hash 
                  clonedLink.href = newHref.substring(0, indexOfQuest + 1) + 'jbUpdateLinksId=' + messageId + '&' + 
                                    newHref.substring(indexOfQuest + 1);
                }
                else {
                  clonedLink.href += '?' + 'jbUpdateLinksId=' + messageId;
                }
              }
              link.replaceWith(clonedLink);
          }
      }
  };
})();
</script>

by the phpstorm ide for some unsolved debugging reason?

0

Please open File | Settings (Preferences on Mac) | Tools | Web Browsers and Preview & disable both options via drop-down selector for "Reload behavior".

The JS part above comes from a live reload IDE component.

0

Please sign in to leave a comment.