This is particularly useful for logging to avoid accidentally printing
passwords in web server logs.
{ "?" boolean } }
{ $description "Tests whether a URL is relative." } ;
+HELP: redacted-url
+{ $values { "url" url } { "url'" url } }
+{ $description "Outputs a new URL with the password (if specified) replaced with " { $snippet "xxxxx" } ". This is useful for logging utilities where you want to avoid printing out the password in the logs." } ;
+
HELP: secure-protocol?
{ $values { "protocol" string } { "?" boolean } }
{ $description "Tests if protocol connections must be made with secure sockets (SSL/TLS)." }
{ URL" http://www.google.com/" } [
URL" http://www.google.com/"
] unit-test
+
+{ URL" https://host:1234/path" } [ URL" https://host:1234/path" redacted-url ] unit-test
+{ URL" https://user@host:1234/path" } [ URL" https://user@host:1234/path" redacted-url ] unit-test
+{ URL" https://user:xxxxx@host:1234/path" } [ URL" https://user:password@host:1234/path" redacted-url ] unit-test
[ [ anchor>> ] either? >>anchor ]
} 2cleave ;
+: redacted-url ( url -- url' )
+ clone [ "xxxxx" and ] change-password ;
+
! Half-baked stuff follows
: secure-protocol? ( protocol -- ? )
"https" = ;