MCPcopy Index your code
hub / github.com/wendux/fly / makeRequest

Method makeRequest

_.js:118–274  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

116
117 // make the http request
118 function makeRequest(options) {
119 data = options.body;
120 // Normalize the request url
121 url = utils.trim(options.url);
122 var baseUrl = utils.trim(options.baseURL || "");
123 if (!url && isBrowser && !baseUrl) url = location.href;
124 if (url.indexOf("http") !== 0) {
125 var isAbsolute = url[0] === "/";
126 if (!baseUrl && isBrowser) {
127 var arr = location.pathname.split("/");
128 arr.pop();
129 baseUrl = location.protocol + "//" + location.host + (isAbsolute ? "" : arr.join("/"))
130 }
131 if (baseUrl[baseUrl.length - 1] !== "/") {
132 baseUrl += "/"
133 }
134 url = baseUrl + (isAbsolute ? url.substr(1) : url)
135 if (isBrowser) {
136
137 // Normalize the url which contains the ".." or ".", such as
138 // "http://xx.com/aa/bb/../../xx" to "http://xx.com/xx" .
139 var t = document.createElement("a");
140 t.href = url;
141 url = t.href;
142 }
143 }
144
145 var responseType = utils.trim(options.responseType || "")
146 engine.withCredentials = !!options.withCredentials;
147 var isGet = options.method === "GET";
148 if (isGet) {
149 if (data) {
150 if (utils.type(data) !== "string") {
151 data = utils.formatParams(data);
152 }
153 url += (url.indexOf("?") === -1 ? "?" : "&") + data;
154 }
155 }
156 engine.open(options.method, url);
157
158 // try catch for ie >=9
159 try {
160 engine.timeout = options.timeout || 0;
161 if (responseType !== "stream") {
162 engine.responseType = responseType
163 }
164 } catch (e) {
165 }
166
167 var customContentType = options.headers[contentType] || options.headers[contentType.toLowerCase()];
168
169 // default content type
170 var _contentType = "application/x-www-form-urlencoded";
171 // If the request data is json object, transforming it to json string,
172 // and set request content-type to "json". In browser, the data will
173 // be sent as RequestBody instead of FormData
174 if (utils.trim((customContentType || "").toLowerCase()) === _contentType) {
175 data = utils.formatParams(data);

Callers

nothing calls this directly

Calls 7

onresultFunction · 0.85
onerrorFunction · 0.85
openMethod · 0.80
setRequestHeaderMethod · 0.80
getResponseHeaderMethod · 0.80
getAllResponseHeadersMethod · 0.80
sendMethod · 0.80

Tested by

no test coverage detected