Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#36 try to be able to customize jquery ajax request in requestURI method #37

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions web.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ $rdf.Fetcher = function(store, timeout, async) {
** Changed 2013-08-20: Added (ok, body) params to callback
**
**/
this.nowOrWhenFetched = function(uri, referringTerm, callback) {
this.nowOrWhenFetched = function(uri, referringTerm, callback, options) {
var sta = this.getState(uri);
if (sta == 'fetched') return callback(true);
this.addCallback('done', function(uri2) {
Expand All @@ -562,8 +562,7 @@ $rdf.Fetcher = function(store, timeout, async) {
false, "Asynch fetch fail: " + status + " for " + uri);
return (uri2 != uri); // Call me again?
});
if (sta == 'unrequested') this.requestURI(
uri, referringTerm, false);
if (sta == 'unrequested') this.requestURI(uri, referringTerm, false, options);
}


Expand Down Expand Up @@ -597,14 +596,19 @@ $rdf.Fetcher = function(store, timeout, async) {
/** Requests a document URI and arranges to load the document.
** Parameters:
** term: term for the thing whose URI is to be dereferenced
** rterm: the resource which refered to this (for tracking bad links)
** force: Load the data even if loaded before
** rterm: the resource which refered to this (for tracking bad links)
** force: Load the data even if loaded before
** options
**
** Options available are:
** - jqueryAjaxOptions: an object that permits to override JQuery.ajax default settings
**
** Return value:
** The xhr object for the HTTP access
** null if the protocol is not a look-up protocol,
** or URI has already been loaded
*/
this.requestURI = function(docuri, rterm, force) { //sources_request_new
this.requestURI = function(docuri, rterm, force, options) { //sources_request_new
if (docuri.indexOf('#') >= 0) { // hash
throw ("requestURI should not be called with fragid: " + docuri);
}
Expand Down Expand Up @@ -960,11 +964,10 @@ $rdf.Fetcher = function(store, timeout, async) {
} else {
// $rdf.log.warn("Localhost kludge OFF offline use: actually getting <" + uri2 + ">");
}


// Setup the request
if (typeof jQuery !== 'undefined' && jQuery.ajax) {
var xhr = jQuery.ajax({
var defaultJQueryAjaxSettings = {
url: uri2,
accepts: {'*': 'text/turtle,text/n3,application/rdf+xml'},
processData: false,
Expand All @@ -981,7 +984,16 @@ $rdf.Fetcher = function(store, timeout, async) {
success: function(d, s, xhr) {
onreadystatechangeFactory(xhr)();
}
});
};

// We merge the default ajax settings with the settings set as option so that the options settings
// can eventually override the default settings
// This can be useful to add an extra request header for exemple
// see https://github.com/linkeddata/rdflib.js/issues/36
var jqueryAjaxOptions = options && options.jqueryAjaxOptions ? options.jqueryAjaxOptions : {};
var finalSettings = $.extend(defaultJQueryAjaxSettings,jqueryAjaxOptions);

var xhr = jQuery.ajax(finalSettings);
} else {
var xhr = $rdf.Util.XMLHTTPFactory();
xhr.onerror = onerrorFactory(xhr);
Expand Down Expand Up @@ -1141,7 +1153,7 @@ $rdf.Fetcher = function(store, timeout, async) {
kb.add(xhr.uri, kb.sym('http://www.w3.org/2007/ont/link#warning'), msg)
newURI = newURI.slice(0, hash);
}
var xhr2 = sf.requestURI(newURI, xhr.uri);
var xhr2 = sf.requestURI(newURI, xhr.uri, undefined, options);
if (xhr2 && xhr2.req) kb.add(xhr.req,
kb.sym('http://www.w3.org/2007/ont/link#redirectedRequest'),
xhr2.req, sf.appNode);
Expand Down