Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test.before(t => {
// note: not bothering to restore this after the test, because anyway
// the "real" one doesn't exist in non-browser situation
xhr.XMLHttpRequest = fakeXhr = sinon.useFakeXMLHttpRequest()
})
* @param {Object} responseHandler
* @param {Object} data
*/
Envjs.connection = function(xhr, responseHandler, data) {
throw new Error('Envjs.connection');
// THIS WILL BE REPLACED WITH NATIVE XHR IMPL
};
// XHR is a confusing bit of code in envjs. Need to simplify.
// if you are lucky your impl has a XHR already
var XMLHttpRequestCore = require('xhr').XMLHttpRequest;
XMLHttpRequest = function() {
XMLHttpRequestCore.apply(this, arguments);
};
XMLHttpRequest.prototype = new XMLHttpRequestCore();
XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
// resolve relative URLs (server-side version doesn't do this,
// require absolute urls)
//print("******* " + url);
if (document.location) {
url = Envjs.uri(url, document.location.href);
} else {
// sometimes document.location is null
// should we always use baseURI?
url = Envjs.uri(url, document.baseURI);
}
//print("******* " + url);
require('xhr').XMLHttpRequest.prototype.open.apply(this, arguments);
this.setRequestHeader('User-Agent', window.navigator.userAgent);
this.setRequestHeader('Accept', 'image/png,image/*;q=0.8,*/*;q=0.5');
function Request() {
var XHR;
if (typeof global.Titanium !== 'undefined' && typeof global.Titanium.Network.createHTTPClient != 'undefined') {
XHR = global.Titanium.Network.createHTTPClient();
} else if (typeof require !== 'undefined') {
// CommonJS require
XHR = new require("xhr").XMLHttpRequest();
} else {
// W3C
XHR = new global.XMLHttpRequest();
}
return XHR;
}
function SHA1(message) {
function Request() {
var XHR;
if (typeof global.Titanium !== 'undefined' && typeof global.Titanium.Network.createHTTPClient != 'undefined') {
XHR = global.Titanium.Network.createHTTPClient();
} else if (typeof require !== 'undefined') {
// CommonJS require
try {
XHR = new require("xhr").XMLHttpRequest();
} catch (e) {
// module didn't expose correct API or doesn't exists
if (typeof global.XMLHttpRequest !== "undefined") {
XHR = new global.XMLHttpRequest();
} else {
throw "No valid request transport found.";
}
}
} else if (typeof global.XMLHttpRequest !== "undefined") {
// W3C
XHR = new global.XMLHttpRequest();
} else {
throw "No valid request transport found.";
}
return XHR;
function Request() {
var XHR;
if (typeof global.Titanium !== 'undefined' && typeof global.Titanium.Network.createHTTPClient != 'undefined') {
XHR = global.Titanium.Network.createHTTPClient();
} else if (typeof require !== 'undefined') {
// CommonJS require
try {
XHR = new require("xhr").XMLHttpRequest({ mozSystem: true });
} catch (e) {
// module didn't expose correct API or doesn't exists
if (typeof global.XMLHttpRequest !== "undefined") {
XHR = new global.XMLHttpRequest({ mozSystem: true });
} else {
throw "No valid request transport found.";
}
}
} else if (typeof global.XMLHttpRequest !== "undefined") {
// W3C
XHR = new global.XMLHttpRequest({ mozSystem: true });
} else {
throw "No valid request transport found.";
}
return XHR;
if(request.name){
name = request.name;
}else{
name = enc.substr(enc.length/2 - 6, 6) + '.' + mime.split('/')[1];
}
callback({
data: data,
type: mime,
id: request.id,
size: data.length,
name: name
});
//callback(new dFile(data, name, mime, id, size)
}else{
var xhr = new XMLHttpRequest();
xhr.open('GET', request.url, true);
if(type == 'binary' || type == 'raw'){
xhr.overrideMimeType('text/plain; charset=x-user-defined'); //should i loop through and do that & 0xff?
}
xhr.onload = function(){
console.log('opened via xhr ', request.url);
var raw = xhr.responseText, data = '';
//for(var l = raw.length, i=0; i
function getPage(worker, message) {
try {
console.log("getPage: " + message.value);
var req = new xhr.XMLHttpRequest();
req.onreadystatechange = function () {
if (req.readyState !== 4) {
return;
}
worker.postMessage({
action : "data",
status : true,
value : {
status : req.status,
statusText : req.statusText,
responseText : req.responseText,
errorThrown : ""
}
});
};
function processNextTask() {
var req = new xhr.XMLHttpRequest();
var url = "http://localhost:8888/api/task-queue/get";
req.open("GET", url);
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
if (req.responseText) {
runTask(JSON.parse(req.responseText));
} else
processNextTask();
} else {
require("timer").setTimeout(processNextTask, 1000);
}
}
};
req.send(null);
}
function postJSON(url, data, callback){
var xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xhr.send(Object.keys(data).map(function(i){
return i+'='+encodeURIComponent(data[i]);
}).join('&'));
xhr.onreadystatechange = function () {
if(this.readyState == 4) {
if(this.status == 200) {
var stuff = JSON.parse(xhr.responseText);
callback(stuff)
} else {
callback(null);
}
}
};
}
function uploadImageshack(file, callback){
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://www.imageshack.us/upload_api.php");
xhr.onload = function(){
try{
var link = xhr.responseXML.getElementsByTagName('image_link');
callback(link[0].childNodes[0].nodeValue);
}catch(err){
callback('error: imageshack uploading failed')
}
}
xhr.onerror = function(){
callback('error: imageshack uploading failed')
}
xhr.sendMultipart({
key: "39ACEJNQa5b92fbce7fd90b1cb6f1104d728eccb",
fileupload: file
})