Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
ef9d0680
...
ef9d06806eca6870f8255e429b5b6acbd414ca84
authored
2012-07-19 11:11:07 +0200
by
oncletom
Committed by
Nicolas Perriault
2012-10-18 09:43:58 +0200
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Implementing the new API
1 parent
860b73c1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
33 deletions
modules/casper.js
modules/casper.js
View file @
ef9d068
...
...
@@ -733,39 +733,6 @@ Casper.prototype.getCurrentUrl = function getCurrentUrl() {
};
/**
* Retrieves all the currentResponse headers
* Each item follows this structure: `{name: 'Header-Name', value: 'Header-Value'}`.
*
* @return Array
*/
Casper
.
prototype
.
getCurrentHeaders
=
function
getCurrentHeaders
()
{
"use strict"
;
return
this
.
currentResponse
===
undefined
?
[]
:
this
.
currentResponse
.
headers
;
};
/**
* Retrieves a given header based on its name
*
* @param String name A case-sensitive response header name
* @return mixed A header string or `null` if not found
*/
Casper
.
prototype
.
getCurrentHeader
=
function
getCurrentHeader
(
name
)
{
"use strict"
;
var
headerValue
=
null
;
this
.
getCurrentHeaders
().
some
(
function
(
header
){
if
(
header
.
name
===
name
){
headerValue
=
header
.
value
;
return
true
;
}
});
return
headerValue
;
};
/**
* Retrieves the value of an attribute on the first element matching the provided
* DOM CSS3/XPath selector.
*
...
...
@@ -1661,6 +1628,33 @@ Casper.extend = function(proto) {
exports
.
Casper
=
Casper
;
/*
* Building an Array subclass
*/
function
responseHeaders
(){}
responseHeaders
.
prototype
=
new
Array
;
/**
* Retrieves a given header based on its name
*
* @param String name A case-sensitive response header name
* @return mixed A header string or `null` if not found
*/
responseHeaders
.
prototype
.
get
=
function
get
(
name
){
"use strict"
;
var
headerValue
=
null
;
this
.
some
(
function
(
header
){
if
(
header
.
name
===
name
){
headerValue
=
header
.
value
;
return
true
;
}
});
return
headerValue
;
};
/**
* Creates a new WebPage instance for Casper use.
*
...
...
@@ -1755,6 +1749,8 @@ function createPage(casper) {
return
casper
.
filter
(
'page.prompt'
,
message
,
value
);
};
page
.
onResourceReceived
=
function
onResourceReceived
(
resource
)
{
resource
.
headers
.
__proto__
=
responseHeaders
.
prototype
;
casper
.
emit
(
'resource.received'
,
resource
);
if
(
utils
.
isFunction
(
casper
.
options
.
onResourceReceived
))
{
casper
.
options
.
onResourceReceived
.
call
(
casper
,
casper
,
resource
);
...
...
Please
register
or
sign in
to post a comment