Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to redact password from URL in Rust?

This question is similar to this one but specific to . How can I readact password from a URL?. This is mainly for logging purposes.

To make it clear I am looking for similar kind of API in .

>>> from pip._internal.utils.misc import redact_auth_from_url
>>> 
>>> redact_auth_from_url("https://user:password@example.com/path?key=value#hash")
'https://user:****@example.com/path?key=value#hash'
>>> redact_auth_from_url.__doc__
'Replace the password in a given url with ****.'

I did check the rust-url crate but I could not find an equivalent function.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could use set_password in conjunction with password:

if url.password().is_some() {
    url.set_password(Some("****"));
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading