Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add cookie for Xdebug in Paw

I debug my API using Xdebug and PHPStorm's debugging features. For this to work, the client needs a cookie named XDEBUG_SESSION.

When using Postman, I used to use a Chrome extension to add this cookie, and Postman's cookie interception feature to get this to work in Postman (since it's a sandboxed app).

However, I cannot create cookies in Paw. So, as a workaround, I modified the API response cookie to have the key as XDEBUG_SESSION and value as PHPSTORM, and debugging worked fine. However, this is not ideal as I would also like to set the expiry date to something far in the future (which I can't in Paw).

So, my questions are:

  • Is there a way to add custom cookies in Paw?
  • If not, is there a way to to edit the expiry date for an existing cookie (considering that name, value, domain and path are editable)?
  • Are there any other alternatives to achieve my objective?
like image 491
robinmitra Avatar asked Dec 20 '14 12:12

robinmitra


2 Answers

I just managed to achieve this exact thing to debug my APIs with Paw (2.1.1).

You just have to Add a Header with the name Cookie and a value of Cookies picked from the dropdown that will appear. You then have to insert a Cookie named XDEBUG_SESSION with a value of PHPSTORM inside the Cookies value of the header just created.

To be more clear, you can see it in the screenshot below:

enter image description here

like image 195
Antonio Frignani Avatar answered Sep 24 '22 04:09

Antonio Frignani


I messed around with it to see if I could create an extension. I wasn't able to, and the below does not work but thought I'd share in case anyone knows the missing pieces.

First off, there is no extension category (generator, dynamic value, importer) that this functionality falls into. I tried to make use of the dynamic value category but was unsuccessful:

CookieInjector = function(key, value) {

    this.key = "XDEBUG_SESSION";
    this.value = "PHPSTORM";

    this.evaluate = function () {
        var f = function (x,y) {
                document.cookie=this.key+"="+this.value;
                return true;
        }
        return f(this.key, this.value);
    }

    // Title function: takes no params, should return the string to display as
    // the Dynamic Value title
    this.title = function() {
        return "Cookie"
    }

    // Text function: takes no params, should return the string to display as
    // the Dynamic Value text
    this.text = function() {
        return this.key+"="+this.value;
    }
}

// Extension Identifier (as a reverse domain name)
CookieInjector.identifier = "com.luckymarmot.PawExtensions.CookieInjector";

// Extension Name
CookieInjector.title = "Inject Cookie Into Cookie Jar";

// Dynamic Value Inputs
CookieInjector.inputs = [
    DynamicValueInput("key", "Key", "String"),
    DynamicValueInput("value", "Value", "String")
]

// Register this new Extension
registerDynamicValueClass(CookieInjector);

The main thing stopping this from working is I'm not sure how the request is built in PAW and not sure how to attach the cookie. I've looked through the documentation here: https://luckymarmot.com/paw/doc/Extensions/Reference/Reference, and can't find what I need.

like image 30
Bryce Avatar answered Sep 24 '22 04:09

Bryce