Skip to content

Commit 537f5bb

Browse files
author
SReject
committed
Migrating to WHR over XHR; adding redirect control
1 parent 9c5332d commit 537f5bb

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

src/JSON For mIRC.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
};
3030

3131
// http/web object detection
32-
HTTPObject = ['MSXML2.SERVERXMLHTTP.6.0', 'MSXML2.SERVERXMLHTTP.3.0', 'MSXML2.SERVERXMLHTTP'].find(function (xhr) {
32+
HTTPObject = ['WinHttp.WinHttpRequest.5.1'].find(function (whr) {
3333
try {
34-
return new ActiveXObject(xhr), xhr;
34+
return new ActiveXObject(whr), whr;
3535
} catch (ignore) {}
3636
});
3737

@@ -145,16 +145,16 @@
145145
this._json = json;
146146
}
147147
this._state = parent._state || 'init';
148-
this._type = parent._type || 'text';
148+
this._type = parent._type || 'text';
149149
this._parse = parent._parse === false ? false : true;
150150
this._error = parent._error || false;
151151
this._input = parent._input;
152-
// (slv) Added 'insecure'
153152
this._http = parent._http || {
154153
method: 'GET',
155154
url: '',
156155
headers: [],
157-
insecure: false
156+
insecure: false,
157+
redirects: true
158158
};
159159
}
160160

@@ -246,11 +246,14 @@
246246
request = new ActiveXObject(HTTPObject);
247247
this._http.response = request;
248248

249-
// Option to ignore all ssl certificate errors
250-
// https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms763811(v=vs.85)
251-
// https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms753798(v=vs.85)
252-
if (this._http.insecure === true) {
253-
request.setOption(2, 13056);
249+
// If indicated, ignore all ssl certificate errors
250+
if (this._http.insecure) {
251+
request.Options(4) = 13056;
252+
}
253+
254+
// If indicated, do not follow redirects
255+
if (!this._http.redirects) {
256+
request.Options(6) = false;
254257
}
255258

256259
// initialize the request
@@ -566,7 +569,7 @@
566569

567570
root.JSONInstance = JSONInstance;
568571

569-
root.JSONCreate = function(type, source, parse, insecure) {
572+
root.JSONCreate = function(type, source, parse, insecure, redirects) {
570573
var self = new JSONInstance();
571574
self._state = 'init';
572575
self._type = (type || 'text').toLowerCase();
@@ -580,6 +583,8 @@
580583
self._state = 'http_pending';
581584
self._http.url = source;
582585
self._http.insecure = insecure;
586+
self._http.redirects = redirects;
587+
583588
} else {
584589
self._state = 'parse_pending';
585590
self._input = source;

0 commit comments

Comments
 (0)