1.0.2 • Published 4 months ago

@warren-bank/htaccess-tester v1.0.2

Weekly downloads
-
License
GPL-2.0
Repository
github
Last release
4 months ago

htaccess-tester

Apache .htaccess Tester

Usage:

  const htaccess_tester = require('@warren-bank/htaccess-tester')

  const test_data = {
    "url":      "http://fdroid.example.com/repo/com.example.app/de/icon.png",
    "htaccess": [
      `RewriteEngine on`,
      `RewriteCond %{HTTP_REFERER} =http://example.com`,
      `RewriteCond %{SSL:SSL_CIPHER_USEKEYSIZE} =128`,
      `RewriteCond %{HTTP:ACCEPT} =text/plain`,
      `RewriteCond expr "%{HTTP:AUTHORIZATION} == 'Basic %{ENV:BASIC_AUTHORIZATION}'"`,
      `RewriteRule "^(/?(?:repo|archive))/([^/]+)/[^/]+/icon.*\\.png$" "$1/icons/$2.png" [BCTLS,PT]`,
      `RewriteRule "^/?repo/icons(?:-\\d+)?/(com\\.example\\.app)(?:\\.\\d+)?\\.png$" "http://icons.example.com/$1/icon.png" [L,R=301]`
    ],
    "variables": {
      "server": {
        "HTTP_REFERER": "http://example.com"
      },
      "environment": {
        "BASIC_AUTHORIZATION": "YWxhZGRpbjpvcGVuc2VzYW1l"
      },
      "ssl-environment": {
        "SSL_CIPHER_USEKEYSIZE": "128"
      },
      "http-header": {
        "ACCEPT":        "text/plain",
        "AUTHORIZATION": "Basic YWxhZGRpbjpvcGVuc2VzYW1l"
      }
    }
  }

  const test_results = htaccess_tester(test_data)

  console.log(
    JSON.stringify(test_results, null, 2)
  )

Output: log file


Browser Build

CDN links:

Usage:

  <html>
    <head>
      <script src="./browser-build/dist/es5/htaccess-tester.js"></script>
      <script>
        // abbreviated.. same data structure as the previous example:
        const test_data = {url, htaccess, variables}

        const test_results = window.htaccess_tester(test_data)
      </script>
    </head>
  </html>

Example: HTML file raw.githack.com


Inspiration:

  • library: htaccess-parser
    • author: Mickael Burguet
    • npm
    • github
    • license: MIT
    • notes:
      • this library serves as a foundation for converting lines of text in .htaccess file format to object models
  • library: express-htaccess-middleware
    • author: Mickael Burguet
    • npm
    • github
    • license: MIT
    • notes:
      • this library has an entirely different purpose, but I used its overall design as a starting point
  • client-side user interface
    • author: madewithlove.com
    • web
    • api
    • notes:
      • this is a great utility, but all of its work is performed by a closed-source api backend
      • I designed my SPA front-end user interface to look similar,and all of its work is performed by client-side JS

Legal:

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago