(options)
| 118 | |
| 119 | // make the http request |
| 120 | function makeRequest(options) { |
| 121 | data = options.body; |
| 122 | // Normalize the request url |
| 123 | url = utils.trim(options.url); |
| 124 | let baseUrl = utils.trim(options.baseURL || ""); |
| 125 | if (!url && isBrowser && !baseUrl) url = location.href; |
| 126 | if (url.indexOf("http") !== 0) { |
| 127 | let isAbsolute = url[0] === "/"; |
| 128 | if (!baseUrl && isBrowser) { |
| 129 | let arr = location.pathname.split("/"); |
| 130 | arr.pop(); |
| 131 | baseUrl = location.protocol + "//" + location.host + (isAbsolute ? "" : arr.join("/")) |
| 132 | } |
| 133 | if (baseUrl[baseUrl.length - 1] !== "/") { |
| 134 | baseUrl += "/" |
| 135 | } |
| 136 | url = baseUrl + (isAbsolute ? url.substr(1) : url) |
| 137 | if (isBrowser) { |
| 138 | |
| 139 | // Normalize the url which contains the ".." or ".", such as |
| 140 | // "http://xx.com/aa/bb/../../xx" to "http://xx.com/xx" . |
| 141 | let t = document.createElement("a"); |
| 142 | t.href = url; |
| 143 | url = t.href; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | let responseType = utils.trim(options.responseType || "") |
| 148 | let needQuery = ["GET", "HEAD", "DELETE", "OPTION"].indexOf(options.method) !== -1; |
| 149 | let dataType = utils.type(data); |
| 150 | let params = options.params || {}; |
| 151 | |
| 152 | // merge url params when the method is "GET" (data is object) |
| 153 | if (needQuery && dataType === "object") { |
| 154 | params = utils.merge(data, params) |
| 155 | } |
| 156 | // encode params to String |
| 157 | params = utils.formatParams(params); |
| 158 | |
| 159 | // save url params |
| 160 | let _params = []; |
| 161 | if (params) { |
| 162 | _params.push(params); |
| 163 | } |
| 164 | // Add data to url params when the method is "GET" (data is String) |
| 165 | if (needQuery && data && dataType === "string") { |
| 166 | _params.push(data); |
| 167 | } |
| 168 | |
| 169 | // make the final url |
| 170 | if (_params.length > 0) { |
| 171 | url += (url.indexOf("?") === -1 ? "?" : "&") + _params.join("&"); |
| 172 | } |
| 173 | |
| 174 | engine.open(options.method, url); |
| 175 | |
| 176 | // try catch for ie >=9 |
| 177 | try { |
nothing calls this directly
no test coverage detected