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