http_type/protocol/impl.rs
1use super::*;
2
3/// Implementation of protocol identification and port resolution methods.
4///
5/// This implementation block provides utility functions for working with
6/// HTTP protocol strings, enabling identification of HTTP/HTTPS variants
7/// and retrieval of their standard port numbers.
8impl Protocol {
9 /// Checks if the given protocol string represents HTTP.
10 ///
11 /// Performs a case-insensitive comparison against the HTTP protocol identifier.
12 ///
13 /// # Arguments
14 /// - `&str`: A string slice representing the protocol to check.
15 ///
16 /// # Returns
17 /// - `bool`: Returns `true` if the protocol is HTTP (case-insensitive), `false` otherwise.
18 #[inline(always)]
19 pub fn is_http(protocol: &str) -> bool {
20 matches!(protocol.to_lowercase().as_str(), HTTP_LOWERCASE)
21 }
22
23 /// Checks if the given protocol string represents HTTPS.
24 ///
25 /// Performs a case-insensitive comparison against the HTTPS protocol identifier.
26 ///
27 /// # Arguments
28 /// - `&str`: A string slice representing the protocol to check.
29 ///
30 /// # Returns
31 /// - `bool`: Returns `true` if the protocol is HTTPS (case-insensitive), `false` otherwise.
32 #[inline(always)]
33 pub fn is_https(protocol: &str) -> bool {
34 matches!(protocol.to_lowercase().as_str(), HTTPS_LOWERCASE)
35 }
36
37 /// Returns the default port number for the given protocol.
38 ///
39 /// Performs a case-insensitive comparison to determine the protocol type
40 /// and returns the corresponding standard port number.
41 ///
42 /// # Arguments
43 /// - `&str`: A string slice representing the protocol to lookup.
44 ///
45 /// # Returns
46 /// - `u16`: The default port number for the protocol.
47 #[inline(always)]
48 pub fn get_port(protocol: &str) -> u16 {
49 match protocol.to_lowercase().as_str() {
50 HTTP_LOWERCASE => 80,
51 HTTPS_LOWERCASE => 443,
52 FTP_LOWERCASE => 21,
53 FTPS_LOWERCASE => 990,
54 SFTP_LOWERCASE => 22,
55 SSH_LOWERCASE => 22,
56 TELNET_LOWERCASE => 23,
57 SMTP_LOWERCASE => 25,
58 SMTPS_LOWERCASE => 465,
59 POP3_LOWERCASE => 110,
60 POP3S_LOWERCASE => 995,
61 IMAP_LOWERCASE => 143,
62 IMAPS_LOWERCASE => 993,
63 DNS_LOWERCASE => 53,
64 WS_LOWERCASE => 80,
65 WSS_LOWERCASE => 443,
66 _ => 80,
67 }
68 }
69}