-
Notifications
You must be signed in to change notification settings - Fork 981
Conversation
I'm not sure for the Also, I'm thinking a neat API would be something more like: var accept = casper.currentResponse.headers.get('Content-Length'); What do you think? |
|
||
var headerValue = null; | ||
|
||
this.getCurrentHeaders().some(function(header){ |
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.
Why not using forEach
here (or maybe more appropriately filter
)?
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.
Because some
stops the loop on the first true
value returned during iterations.
But I forgot the return true
2 lines below :-D
The advantage is to stop the loop as soon as the header is found.
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.
Ah ok, now I understand it better ;)
Now, I'm wondering if I shouldn't pass the response object to the step callback: casper.start('http://google.com/', function(response) {
if (/json/.test(response.headers.get('Content-Type'))) {
this.echo('JSON spotted');
}
}); That would break any old codebase relying on the deprecated Thoughts? |
Yay, it would be even easier. And shorter to write. And less ambiguous than retrieving |
Okay, pushed a cleaner API and case-insensitive retrieval. |
@@ -1583,6 +1583,34 @@ Casper.extend = function(proto) { | |||
|
|||
exports.Casper = Casper; | |||
|
|||
/* |
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.
What about putting this in a dedicated http
module?
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.
Yep why not. I don't know your plans for this module, as request headers are just a plain object.
Very nice, things are shaping up nicely. Regarding my comment about passing the response as an argument of the step callback, any thought? |
Yep indeed. I may do that in another PR, especially as I've not digged too much in steps and it seems there are some subtle stuff with history etc. |
Finally put the As expected, browsing back and forward does not match with |
@@ -1100,7 +1100,7 @@ Casper.prototype.runStep = function runStep(step) { | |||
}, this.options.stepTimeout, this, new Date().getTime(), this.step); | |||
} | |||
this.emit('step.start', step); | |||
stepResult = step.call(this, this); | |||
stepResult = step.call(this, this.currentResponse || undefined); |
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.
Just this.currentResponse
would suffice
Do you need anything more for this PR? |
How do you access the response headers with the latest pull request? |
Merged |
@Doni documentation is here http://casperjs.org/api.html#casper.then.callbacks |
Helper to easilly access a response header from anywhere.