<commit_before>// @flow
import url from 'url';

/*
 * This is the Hapi route handler that will be applied to the React application
 * route (usually a wildcard handling all paths).
 *
 * It is primarily responsible for two things:
 * 1. Ensure that the current URL pathname matches the language specified by the
 *    request - redirect if not
 * 2. Render the application in the requested language
 *
 * It also calls the tracking plugin in order to handle session tracking.
 */
export default (languageRenderers: { [string]: LanguageRenderer$ }) => (
	request: HapiRequest,
	reply: HapiReply
) => {
	const pathname = request.getLangPrefixPath();
	if (pathname !== request.url.pathname) {
		return reply.redirect(url.format({ ...request.url, pathname }));
	}
	const requestLanguage = request.getLanguage();
	const renderRequest = languageRenderers[requestLanguage];

	renderRequest(request).subscribe(
		(renderResult: RenderResult) => {
			if (renderResult.redirect) {
				return reply
					.redirect(renderResult.redirect.url)
					.permanent(Boolean(renderResult.redirect.permanent));
			}
			return reply(renderResult.result).code(renderResult.statusCode);
		},
		err => reply(err) // 500 error - will only be thrown on bad implementation
	);
};
<commit_msg>revert handler change<commit_after>// @flow
import url from 'url';

/*
 * This is the Hapi route handler that will be applied to the React application
 * route (usually a wildcard handling all paths).
 *
 * It is primarily responsible for two things:
 * 1. Ensure that the current URL pathname matches the language specified by the
 *    request - redirect if not
 * 2. Render the application in the requested language
 *
 * It also calls the tracking plugin in order to handle session tracking.
 */
export default (languageRenderers: { [string]: LanguageRenderer$ }) => (
	request: HapiRequest,
	reply: HapiReply
) => {
	const pathname = request.getLangPrefixPath();
	if (pathname !== request.url.pathname) {
		return reply.redirect(url.format({ ...request.url, pathname }));
	}
	const requestLanguage = request.getLanguage();
	const renderRequest = languageRenderers[requestLanguage];

	renderRequest(request, reply).subscribe(
		(renderResult: RenderResult) => {
			if (renderResult.redirect) {
				return reply
					.redirect(renderResult.redirect.url)
					.permanent(Boolean(renderResult.redirect.permanent));
			}
			return reply(renderResult.result).code(renderResult.statusCode);
		},
		err => reply(err) // 500 error - will only be thrown on bad implementation
	);
};

{'fraction_non_alphanumeric': 0.10665092483274302, 'fraction_numerical': 0.003935458480913027, 'mean_word_length': 4.209016393442623, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2756867', 'n_tokens_mistral': 744, 'n_tokens_neox': 699, 'n_words': 239}