Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var XMLHttpRequestInternal = XMLHttpRequest;
- XMLHttpRequest = function() {
- this.onreadystatechange = function() { };
- this.readyState = 0;
- this.response = null;
- this.responseText = null;
- this.responseType = "";
- this.responseURL = null;
- this.responseXML = null;
- this.status = 0;
- this.statusText = "";
- this._loadcallbacks = [];
- this._errorcallbacks = [];
- this._headers = [];
- this.onload = function(e) {
- }
- this.onerror = function(e) {
- }
- this.onprogress = function(e) {
- }
- this.abort = function() {
- this._aborted = true;
- };
- this.addEventListener = function(event, callback) {
- if(event === "load") {
- this._loadcallbacks.push(callback);
- } else if(event == "error") {
- this._errorcallbacks.push(callback);
- }
- };
- this.getAllResponseHeaders = function() {
- return null;
- };
- this.setRequestHeader = function(header, value) {
- this._headers.push([header, value]);
- }
- this.open = function (method, url, async, user, password) {
- this._method = method;
- this._url = url;
- if(async != null) {
- this._async = async;
- } else {
- this._async = true;
- }
- this._user = user;
- this._password = password;
- };
- this.overrideMimeType = function(mime_type) {
- this._overrideMime = mime_type;
- };
- this.send = function(post_data) {
- if(!this._url) {
- return;
- }
- let this_ref = this;
- if(this._url.includes("vod.dori") == false || true) {
- let xhr = new XMLHttpRequestInternal();
- xhr.responseType = this.responseType;
- if(this._overrideMime) {
- xhr.overrideMimeType(this._overrideMime);
- }
- this.abort = function() {
- xhr.abort();
- }
- this_ref.getAllResponseHeaders = function() {
- return xhr.getAllResponseHeaders;
- }
- this_ref.getResponseHeader = function(name) {
- return xhr.getResponseHeader(name);
- }
- xhr.onload = function() {
- if(xhr.readyState == 4) {
- this_ref.readyState = 1;
- this_ref.onreadystatechange();
- this_ref.readyState = 2;
- this_ref.onreadystatechange();
- this_ref.status = xhr.status;
- this_ref.statusText = xhr.statusText;
- this_ref.readyState = 3;
- this_ref.onreadystatechange();
- this_ref.response = xhr.response;
- this_ref.responseText = xhr.responseText;
- this_ref.responseXML = xhr.responseXML;
- this_ref.responseURL = xhr.responseURL;
- this_ref.readyState = 4;
- this_ref.onreadystatechange();
- var event = { target: this_ref };
- this_ref.onload(event);
- for(callback of this_ref._loadcallbacks) {
- callback.call(this_ref, event);
- }
- }
- else {
- this_ref.readyState = xhr.readyState;
- this_ref.onreadystatechange();
- }
- }
- xhr.onerror = function(exception) {
- this_ref.onerror(exception);
- for(callback of this_ref._errorcallbacks) {
- callback.call(this_ref, exception);
- }
- }
- xhr.open(this_ref._method, this_ref._url, this_ref._async, this_ref._user, this_ref._password);
- let num_headers = this_ref._headers.length;
- for(let index = 0; index < num_headers; index += 1) {
- xhr.setRequestHeader(this._headers[index][0], this._headers[index][1]);
- }
- xhr.send(post_data);
- } else {
- let headers = [];
- let num_headers = this_ref._headers.length;
- for(let index = 0; index < num_headers; index += 1) {
- headers.push(this._headers[index][0] + ": ", this._headers[index][1]);
- }
- requester.request(this._url, post_data, headers).then(function(http) {
- this_ref.readyState = 1;
- this_ref.onreadystatechange();
- this_ref.readyState = 2;
- this_ref.onreadystatechange();
- this_ref.status = http.status;
- this_ref.statusText = http.statusText;
- this_ref.readyState = 3;
- this_ref.onreadystatechange();
- let is_xml = false;
- if(this_ref._overrideMime) {
- if(this_ref._overrideMime === "application/xml" || this_ref._overrideMime == "text/xml") {
- is_xml = true;
- }
- } else {
- let headers = http.getAllResponseHeaders().toLowerCase();
- if(headers.includes("content-type: application/xml") || headers.includes("content-type: text/xml")) {
- is_xml = true;
- }
- }
- if(is_xml) {
- parser = new DOMParser();
- this_ref.responseXML = parser.parseFromString(this_ref.responseText, "text/xml");
- }
- this_ref.response = http.response;
- this_ref.responseText = http.responseText;
- this_ref.responseURL = this_ref._url;
- this_ref.readyState = 4;
- this_ref.onreadystatechange();
- var event = { target: this_ref };
- this_ref.onload(event);
- for(callback of this_ref._loadcallbacks) {
- callback.call(this_ref, event);
- }
- }, function(exception) {
- this_ref.onerror(exception);
- for(callback of this_ref._errorcallbacks) {
- callback.call(this_ref, exception);
- }
- });
- }
- };
- };
- XMLHttpRequest.prototype = {
- 'UNSENT': 0,
- 'OPENED': 1,
- 'HEADERS_RECIEVED': 2,
- 'LOADING': 3,
- 'DONE': 4,
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement