<commit_before>var url = require('url');
var extend = require('util')._extend;
var defaultOptions = require('./options');

// Express middleware for canonicalisation of URLs
// between HTTPS and HTTP and www URLs to non-www (apex) URL equivalents.
// Copyright (c) 2014 <NAME>. MIT License.
module.exports = function(hostUrlObject, opts) {
    
    var workingHostUrlObject = extend(hostUrlObject);
    
    var options = opts || defaultOptions;
    
    // The canon should be called as early as possible.
    return function(req, res, next) {        
        // req.url from Express returns the relative URL (path) after the hostname.
    
        var workingUrl = req.url;
        
        // Proper original URL, not path.
        var originalUrlObject = {}
        originalUrlObject.protocol = req.protocol;
        originalUrlObject.hostname = req.hostname;
        originalUrlObject.pathname = req.url;
        var originalUrl = req.url;
        if (options.isProduction) {
            originalUrl = url.format(originalUrlObject);
        }
            
        var slashCanon = function() {
            // Remove all trailing slashes.
            workingUrl = workingUrl.replace(/\/+$/g, '');<commit_msg>logging<commit_after>var url = require('url');
var extend = require('util')._extend;
var defaultOptions = require('./options');

// Express middleware for canonicalisation of URLs
// between HTTPS and HTTP and www URLs to non-www (apex) URL equivalents.
// Copyright (c) 2014 <NAME>. MIT License.
module.exports = function(hostUrlObject, opts) {
    
    var workingHostUrlObject = extend(hostUrlObject);
    
    var options = opts || defaultOptions;
    
    // The canon should be called as early as possible.
    return function(req, res, next) {        
        // req.url from Express returns the relative URL (path) after the hostname.
    
        var workingUrl = req.url;
        
        // Proper original URL, not path.
        var originalUrlObject = {}
        originalUrlObject.protocol = req.protocol;
        originalUrlObject.hostname = req.hostname;
        originalUrlObject.pathname = req.url;
        var originalUrl = req.url;
        
        console.log('req.url:' + req.url);
        console.log('originalUrlObject:' + JSON.stringify(originalUrlObject));
        console.log('originalUrl:' + originalUrl);
        
        if (options.isProduction) {
            originalUrl = url.format(originalUrlObject);
        }
            
        var slashCanon = function() {
            // Remove all trailing slashes.
            workingUrl = workingUrl.replace(/\/+$/g, '');
{'fraction_non_alphanumeric': 0.10617094672288233, 'fraction_numerical': 0.0030663089306247606, 'mean_word_length': 2.3461538461538463, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3445010', 'n_tokens_mistral': 702, 'n_tokens_neox': 685, 'n_words': 204}