From b7ac95d8eaed0dacae22e7a0b43cd7504a244514 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Sat, 6 Apr 2024 20:46:41 +0900 Subject: [PATCH] Fix #111 --- lib/http.js | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/lib/http.js b/lib/http.js index fceea14..fa8109c 100644 --- a/lib/http.js +++ b/lib/http.js @@ -178,9 +178,15 @@ var HTTPObject = function(engine) { this.setContentType = function(type) { this.contentType = type; + this.setHeader("Content-Type", this.contentType); return this; }; + this.setCookie = function(cookie) { + this.cookie = cookie; + this.setHeader("Cookie", this.cookie); + }; + this.setRequestBody = function(data) { this.requestBody = data; return this; @@ -196,10 +202,6 @@ var HTTPObject = function(engine) { return this; }; - this.setCookie = function(cookie) { - this.cookie = cookie; - }; - this.setHeaders = function(headers) { try { var headers = (typeof(headers) !== "undefined") ? headers : {}; @@ -360,7 +362,7 @@ var HTTPObject = function(engine) { this.setMethod(method.toUpperCase()); // set method this.pushState(null, null, url); // push state - this.setHeader("User-Agent", (this.userAgent != null ? this.evaluate(this.userAgent) : '')); // user agent + this.setHeader("User-Agent", this.evaluate(this.userAgent)); // user agent try { if (this.engine == "MSXML") { @@ -395,27 +397,27 @@ var HTTPObject = function(engine) { // [lib/http] cURL error with non-escaped ampersand on Command Prompt #103 var replaceAndExcludeCaretAnd = function(inputString) { - var result = ""; - var i = 0; - - while (i < inputString.length) { - // If the found position is ^&, do not modify and add it as is to the result - if (i < inputString.length - 1 && inputString.slice(i, i + 2) === "^&") { - result += inputString.slice(i, i + 2); - i += 2; - } else { - // Replace & with ^& - if (inputString.charAt(i) === "&") { - result += "^&"; + var result = ""; + var i = 0; + + while (i < inputString.length) { + // If the found position is ^&, do not modify and add it as is to the result + if (i < inputString.length - 1 && inputString.slice(i, i + 2) === "^&") { + result += inputString.slice(i, i + 2); + i += 2; } else { - result += inputString.charAt(i); + // Replace & with ^& + if (inputString.charAt(i) === "&") { + result += "^&"; + } else { + result += inputString.charAt(i); + } + i++; } - i++; } - } - return result; - }; + return result; + }; if (this.contentType != null) { this.setHeader("Content-Type", this.contentType); @@ -480,7 +482,7 @@ var HTTPObject = function(engine) { } cmd.push("-A"); - cmd.push((this.userAgent != null ? this.evaluate(this.userAgent) : '')); + cmd.push(this.evaluate(this.userAgent)); // --connect-timeout if (this.connectTimeout > 0) { @@ -717,6 +719,8 @@ var HTTPObject = function(engine) { }; this.evaluate = function(str) { + if (typeof str === "undefined" || str == null) return ''; + var str = String(str); var Lpos = str.indexOf('{'); var Rpos = str.indexOf('}', Lpos + 1); @@ -1029,7 +1033,7 @@ exports.put = put; exports._delete = _delete; exports.parseURL = parseURL; -exports.VERSIONINFO = "HTTP request module (http.js) version 0.7.13"; +exports.VERSIONINFO = "HTTP request module (http.js) version 0.7.14"; exports.AUTHOR = "abuse@catswords.net"; exports.global = global; exports.require = global.require;