<commit_before>'use strict';

var xsrfToken = require('frau-xsrf-token');

var XSRF_HEADER = 'X-Csrf-Token';

function noop () {}

function isRelative/*ly safe*/ (url) {
	return typeof url === 'string'
		&& url.length > 0
		&& url[0] === '/';
}

module.exports = function getXsrfToken (req) {
	var end = req.end;

	req.end = function getXsrfTokenEndOverride (cb) {
		function completeRequest () {
			req.end = end;
			return req.end(cb);
		}

		if (!isRelative(req.url)) {
			return completeRequest();
		}

		xsrfToken()
			.then(function (token) {
				req.set('X-Csrf-Token', token);
			})
			.catch(noop)
			.then(function () {
				// Run this async in another turn
				// So we don't catch errors with our promise<commit_msg>(refact) make use of XSRF_HEADER var<commit_after>'use strict';

var xsrfToken = require('frau-xsrf-token');

var XSRF_HEADER = 'X-Csrf-Token';

function noop () {}

function isRelative/*ly safe*/ (url) {
	return typeof url === 'string'
		&& url.length > 0
		&& url[0] === '/';
}

module.exports = function getXsrfToken (req) {
	var end = req.end;

	req.end = function getXsrfTokenEndOverride (cb) {
		function completeRequest () {
			req.end = end;
			return req.end(cb);
		}

		if (!isRelative(req.url)) {
			return completeRequest();
		}

		xsrfToken()
			.then(function (token) {
				req.set(XSRF_HEADER, token);
			})
			.catch(noop)
			.then(function () {
				// Run this async in another turn
				// So we don't catch errors with our promise
{'fraction_non_alphanumeric': 0.15853658536585366, 'fraction_numerical': 0.0027100271002710027, 'mean_word_length': 3.22, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2428100', 'n_tokens_mistral': 600, 'n_tokens_neox': 522, 'n_words': 130}