Lowercase

Probe file system for lowercase filename

by Read Write Tools
Abstract
The incoming request path is examined for uppercase letters and the file system is probed with its equivalent lowercase name. If the equivalent filename exists, return with a status code of 302 Found and a location header, instructing the browser to reissue the request.

Motivation

Filenames on Windows are case insensitive, so a request for Hello-World.html and hello-world.html are equivalent. Not so on Linux. These are recognized as two distinct files. Neither way is "right", but moving from one file system to another with names like this is problematic.

Because of this, it has become customary to restrict URL paths to be all lowercase. Websites that started out on a case insensitive file system and were later moved to a case-sensitive file system, may break when external hyperlinks point to the incorrectly cased filename. One solution is to rename all filenames to their lowercase equivalent, and use this plugin to instruct browsers of the change.

The algorithm is straightforward:

  1. Check the file system to see if the requested resource path exists; if so, skip the remaining steps and resume standard processing.
  2. Apply a lowercase filter to the full resource path and filename.
  3. Probe the file system to see if the lowercased version exists:
    • If so, return with 302 Found and a location header containing the correct resource path.
    • If not, return with 404 Not Found.

Customization

This plugin is open source and can be modified or enhanced to perform tasks such as these:

  • Safely reorganize the directory structure of your website, without unnecessarily breaking external links.
  • Define a lookup table with original filenames and archived filenames, where access to archived content is behind a paywall.

Download

The plugin module is available from NPM. Before proceeding, you should already have Node.js and RWSERVE configured and tested.

This module should be installed on your web server in a well-defined place, so that it can be discovered by RWSERVE. The standard place for public domain plugins is /srv/rwserve-plugins.

cd /srv/rwserve-plugins
npm install rwserve-lowercase

Configuration is Everything

Make the software available by declaring it in the plugins section of your configuration file. For detailed instructions on how to do this, refer to the plugins documentation on the Read Write Tools HTTP/2 Server website.

TL;DR

plugins {
rwserve-lowercase {
location `/srv/rwserve-plugins/node_modules/rwserve-lowercase/dist/index.js`
}
router {
`*` *methods=GET,HEAD *plugin=rwserve-lowercase
}
}

The sample router shown above will route all requests (`*`) for GET or HEAD methods, to the plugin.

Cookbook

A full configuration file with typical settings for a server running on localhost port 7443, is included in this NPM module at etc/lowercase-config. To use this configuration file, adjust these variables if they don't match your server setup:

$PLUGIN-PATH='/srv/rwserve-plugins/node_modules/rwserve-lowercase/dist/index.js'
$PRIVATE-KEY='/etc/pki/tls/private/localhost.key'
$CERTIFICATE='/etc/pki/tls/certs/localhost.crt'
$DOCUMENTS-PATH='/srv/rwserve/configuration-docs'

Deployment

Once you've tested the plugin and are ready to go live, adjust your production web server's configuration in /etc/rwserve/rwserve.conf and restart it using systemd. . .

[user@host ~]# systemctl restart rwserve

. . . then monitor its request/response activity with journald.

[user@host ~]# journalctl -u rwserve -ef

Prerequisites

This is a plugin for the Read Write Tools HTTP/2 Server, which works on Linux platforms. Windows, MacOS and BSD are not supported.

Software Minimum Version
Ubuntu 16
Debian 9
Fedora 27
CentOS 7.4
RHEL 8
RWSERVE 1.0
Node.js 10.3

Review

Lessons
This plugin demonstrates a basic pattern that many plugins follow:
  • Adding a standard response header using addStdHeader()
  • Setting an "empty" response body with setEmptyPayload()
  • Setting the response status code with setStatusCode()
Find other plugins for the Read Write Tools HTTP/2 Server using npm with these keywords: rwserve, http2, plugins.

License

The rwserve-lowercase plugin is licensed under the MIT License.

MIT License

Copyright © 2020 Read Write Tools.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Availability

Source code github
Package installation NPM
Documentation Read Write Hub

Lowercase — Probe file system for lowercase filename

🔎