2017-09-28 16:18:12 -07:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {Adapter} from './adapter';
|
|
|
|
|
2017-10-02 15:59:57 -07:00
|
|
|
export function isNavigationRequest(req: Request, relativeTo: string, adapter: Adapter): boolean {
|
2017-09-28 16:18:12 -07:00
|
|
|
if (req.mode !== 'navigate') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (req.url.indexOf('__') !== -1) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-02 15:59:57 -07:00
|
|
|
if (hasFileExtension(req.url, relativeTo, adapter)) {
|
2017-09-28 16:18:12 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!acceptsTextHtml(req)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-02 15:59:57 -07:00
|
|
|
function hasFileExtension(url: string, relativeTo: string, adapter: Adapter): boolean {
|
|
|
|
const path = adapter.parseUrl(url, relativeTo).path;
|
2017-09-28 16:18:12 -07:00
|
|
|
const lastSegment = path.split('/').pop() !;
|
|
|
|
return lastSegment.indexOf('.') !== -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function acceptsTextHtml(req: Request): boolean {
|
|
|
|
const accept = req.headers.get('Accept');
|
|
|
|
if (accept === null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const values = accept.split(',');
|
|
|
|
return values.some(value => value.trim().toLowerCase() === 'text/html');
|
|
|
|
}
|