Update http.js

This commit is contained in:
Namhyeon Go 2022-05-02 23:56:14 +09:00 committed by GitHub
parent 512f0b4cb9
commit 6a13d9437b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,7 +48,9 @@ var HTTPObject = function(engine) {
password: ""
};
this.isFollowRedirect = true;
this.saveTo = '';
this.saveTo = null;
this.isLoggingCookie = false;
this.create = function() {
if (this.engine == "MSXML") {
@ -406,6 +408,11 @@ var HTTPObject = function(engine) {
cmd.push(this.evaluate(this.cookie));
}
if (this.isLoggingCookie) {
cmd.push("-c");
cmd.push("/tmp/cookie.txt");
}
cmd.push("-A");
cmd.push((this.userAgent != null ? this.userAgent : ''));
@ -456,8 +463,10 @@ var HTTPObject = function(engine) {
}
// if it is download
cmd.push("-o");
cmd.push(this.saveTo);
if (this.saveTo != null) {
cmd.push("-o");
cmd.push(this.saveTo);
}
// set the URL
cmd.push(state.url);
@ -668,6 +677,25 @@ var HTTPObject = function(engine) {
return scripts;
};
this.setIsLoggingCookie = function(flag) {
this.isLoggingCookie = flag;
return this;
};
this.getAllCookies = function() {
var data = {};
var rows = splitLn(FILE.readFile("/tmp/cookie.txt"), "utf-8");
for (var i = 0; i < rows.length; i++) {
var cols = rows[i].split("\t");
if (cols.length == 7) {
data[cols[5]] = cols[6];
}
}
return data;
};
this.create();
};
@ -683,6 +711,6 @@ exports.get = function(url, data, headers) {
return (new HTTPObject()).setHeaders(headers).setParameters(data).setUseCache(false).get(url).responseBody;
};
exports.VERSIONINFO = "HTTP Lib (http.js) version 0.5";
exports.VERSIONINFO = "HTTP Lib (http.js) version 0.6";
exports.global = global;
exports.require = global.require;