Skip to content

Commit

Permalink
Merge pull request #27 from tsubik/fallback-request-navigate-fix
Browse files Browse the repository at this point in the history
fallback request with navigate mode fix
  • Loading branch information
jkleinsc authored Jun 24, 2016
2 parents 155daba + efa032a commit eac097a
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions lib/fallback-response.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
function getFallbackFromCache(request, values, options) {
logDebug('Fetching from fallback url: '+ options.fallbackURL +'for url: '+request.url);
var req = new Request(options.fallbackURL, request);
return toolbox.cacheFirst(req, values, options).then(function(response) {
if (response) {
logDebug('Got fallback response from cache',response);
return response;
}
});
return request
.text()
.then(function(text) {
// cannot set mode to navigate in Request constructor init object
// https://fetch.spec.whatwg.org/#dom-request
var mode = request.mode === 'navigate' ? 'same-origin' : request.mode;
var body = text === '' ? undefined : text;
return new Request(options.fallbackURL, {
method: request.method,
headers: request.headers,
body: body,
mode: mode,
credentials: request.credentials,
redirect: request.redirect,
cache: request.cache,
});
})
.then(function(req) {
return toolbox.cacheFirst(req, values, options);
})
.then(function(response) {
if (response) {
logDebug('Got fallback response from cache',response);
return response;
}
});
}

function fallbackResponse(request, values, options) {
Expand Down

0 comments on commit eac097a

Please # to comment.