'use strict'; // XXX
import { Url } from 'url';
import { RedirectInfo, ExtendedRedirectInfo } from '../';


//
// Entry Point
//
export function rewrite(url: Url): ExtendedRedirectInfo {
    const host = '.w3.org';

    if (('.' + url.host).endsWith(host)) {
        if (url.protocol === 'http:') {
            const reason = 'Prefer https: over http:';
            const redirectInfo: RedirectInfo = {
                protocol: 'https:',
            };

            return {
                type: 'rewrite',
                reason: reason,
                redirectInfo: redirectInfo,
            };
        }
    }

    return null;
}

'use strict'; // XXX
import { Url } from 'url';
import { RedirectInfo, ExtendedRedirectInfo } from '../';


//
// dev.w3.org
//
const REDIRECT_MAP: Map<string, string> = new Map([
    ['/csswg/', 'drafts.csswg.org'],
    ['/fxtf/', 'drafts.fxtf.org'],
    ['/houdini/', 'drafts.css-houdini.org'],
]);

function rewriteDevW3Org(url: Url): ExtendedRedirectInfo {
    const pathname = url.pathname;

    for (const pair of REDIRECT_MAP) {
        const knownPathname = pair[0];
        const host = pair[1];

        if (pathname.startsWith(knownPathname)) {
            const newPathname = pathname.substring(knownPathname.length - 1);

            const reason = 'dev.w3.org has retired';
            const redirectInfo: RedirectInfo = {
                protocol: 'https:',
                host: host,
                pathname: newPathname,
            }

            return {
                type: 'rewrite',
                reason: reason,
                redirectInfo: redirectInfo,
            };
        }
    }

    return null;
}


//
// Entry Point
//
export function rewrite(url: Url): ExtendedRedirectInfo {

    if (url.host  === 'dev.w3.org') {
        return rewriteDevW3Org(url);
    }

    return null;
}

Bring back redirecting dev.w3.org to drafts.csswg.org and so on.
Bring back redirecting dev.w3.org to drafts.csswg.org and so on.
