Add cookie for Xdebug to Paw
I am debugging my API using Xdebug and PHPStorm debug functions. For this to work, the client needs a cookie named XDEBUG_SESSION
.
When using Postman, I used the Chrome extension to add this cookie and Postman's cookie interception feature to get this to work in Postman (since it is a sandboxed application).
However, I cannot create cookies in Paw. So, as a workaround, I changed the API responses cookie to have a key as XDEBUG_SESSION
and a value as PHPSTORM
, and debugging worked fine. However, this is not ideal as I would also like to set an expiration date in the future (which I cannot in Paw).
So my questions are:
- Is there a way to add custom cookies to Paw?
- If not, is there a way to change the expiration date of an existing cookie (given that the name, value, domain, and path are editable)?
- Are there any other alternatives to achieve my goal?
source to share
I just managed to achieve this goal in order to debug my APIs using Paw (2.1.1).
You just need to add a title with the name Cookie
and value Cookies
selected from the dropdown that appears. Then you need to insert a Cookie named XDEBUG_SESSION
with a value PHPSTORM
inside the Cookies value of the header you just created.
To be more clear, you can see it in the screenshot below:
source to share
I messed it up to see if I can create an extension. I couldn't and the following didn't work, but I thought I'd share if someone knows the missing parts.
First, there is no extension category (generator, dynamic value, importer) that this functionality belongs to. I tried using dynamic value category but with no success:
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 to stop this from working - I'm not sure how the request is constructed in PAW and not sure how to attach the cookie. I've looked at the documentation here: https://luckymarmot.com/paw/doc/Extensions/Reference/Reference and can't find what I need.
source to share