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
9ad70d39
...
9ad70d393ad07d00f834611b3492ec7e4aa6e3dc
authored
2011-12-21 16:16:20 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge remote-tracking branch 'jasonlfunk/master' into jasonlfunk-integration
2 parents
5319067c
8641c3de
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
12 deletions
lib/casper.js
lib/clientutils.js
lib/casper.js
View file @
9ad70d3
...
...
@@ -120,13 +120,15 @@
*
* NOTE: we cannot use window.btoa() for some strange reasons here.
*
* @param String url The url to download
* @return string Base64 encoded result
* @param String url The url to download
* @param String method The method to use, optional: default GET
* @param String data The data to send, optional
* @return string Base64 encoded result
*/
base64encode
:
function
(
url
)
{
return
this
.
evaluate
(
function
(
url
)
{
return
__utils__
.
getBase64
(
url
);
},
{
url
:
url
});
base64encode
:
function
(
url
,
method
,
data
)
{
return
this
.
evaluate
(
function
(
url
,
method
,
data
)
{
return
__utils__
.
getBase64
(
url
,
method
,
data
);
},
{
url
:
url
,
method
:
method
,
data
:
data
});
},
/**
...
...
lib/clientutils.js
View file @
9ad70d3
...
...
@@ -224,10 +224,12 @@
* contents.
*
* @param String url The resource url
* @param String method The request method, optional
* @param Object data The request data, optional
* @return String Base64 contents string
*/
this
.
getBase64
=
function
(
url
)
{
return
this
.
encode
(
this
.
getBinary
(
url
));
this
.
getBase64
=
function
(
url
,
method
,
data
)
{
return
this
.
encode
(
this
.
getBinary
(
url
,
method
,
data
));
};
/**
...
...
@@ -235,14 +237,38 @@
* fails but log errors.
*
* @param String url
* @param String method
* @param Object data
* @return string
*/
this
.
getBinary
=
function
(
url
)
{
this
.
getBinary
=
function
(
url
,
method
,
data
)
{
try
{
var
xhr
=
new
XMLHttpRequest
();
xhr
.
open
(
"GET"
,
url
,
false
);
if
(
method
===
undefined
||
[
"GET"
,
"get"
,
"POST"
,
"post"
].
indexOf
(
method
)
==
-
1
)
{
method
=
"GET"
;
}
else
{
method
=
method
.
toUpperCase
();
}
xhr
.
open
(
method
,
url
,
false
);
this
.
log
(
"using HTTP method: '"
+
method
+
"'"
,
"debug"
);
xhr
.
overrideMimeType
(
"text/plain; charset=x-user-defined"
);
xhr
.
send
(
null
);
if
(
method
==
"POST"
)
{
if
(
data
===
undefined
)
{
data_str
=
""
;
}
else
{
data_str
=
""
;
for
(
k
in
data
)
{
if
(
typeof
(
k
)
==
"string"
&&
typeof
(
data
[
k
])
==
"string"
)
{
data_str
+=
"&"
+
escape
(
k
)
+
"="
+
escape
(
data
[
k
]);
}
}
data_str
=
data_str
.
substring
(
1
);
}
xhr
.
setRequestHeader
(
"Content-type"
,
"application/x-www-form-urlencoded"
);
}
this
.
log
(
"using request data: '"
+
data_str
+
"'"
,
"debug"
);
xhr
.
send
(
method
==
"POST"
?
data_str
:
null
);
return
xhr
.
responseText
;
}
catch
(
e
)
{
if
(
e
.
name
===
"NETWORK_ERR"
&&
e
.
code
===
101
)
{
...
...
@@ -358,4 +384,4 @@
return
out
;
};
};
})(
phantom
);
\ No newline at end of file
})(
phantom
);
...
...
Please
register
or
sign in
to post a comment