1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#![allow(missing_docs)]
use std::net::SocketAddr;

const HTTP_PREFIX: &str = "http://";

/// Normalize and convert SocketAddr to string
pub fn convert_address_to_normalized_string(addr: &Option<SocketAddr>) -> Option<Vec<u8>> {
	let mut address = match addr {
		None => return None,
		Some(SocketAddr::V4(v4)) => v4.to_string(),
		Some(SocketAddr::V6(v6)) => v6.to_string(),
	};

	if !address.starts_with(HTTP_PREFIX) {
		address = format!("{}{}", HTTP_PREFIX, address);
	}
	Some(address.into_bytes())
}