1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use derive_more::Display;
use native_tls::HandshakeError;
use std::error::Error;
use std::net::TcpStream;
use trust_dns_resolver::error::ResolveError;
use std::io;
#[derive(Debug, Display)]
pub enum ResolveDnsError {
#[display(fmt = "Can't find DNS entry for the given host.")]
NoResults,
#[display(fmt = "Couldn't resolve DNS for given host because: {}", _0)]
Other(ResolveError),
}
impl Error for ResolveDnsError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
ResolveDnsError::Other(err) => Some(err),
ResolveDnsError::NoResults => None,
}
}
}
#[derive(Debug, Display)]
pub enum InvalidUrlError {
#[display(
fmt = "No input provided. Provide a URL, like https://example.com or https://1.2.3.4:443"
)]
MissingInput,
#[display(fmt = "The URL is illegal, because of {}", _0)]
WrongFormat(String),
#[display(fmt = "This tools only supports http and https")]
WrongScheme,
#[display(
fmt = "https can only be used when a domain name is given. IP addresses don't work."
)]
HttpsRequiresDomainName,
Other,
}
impl Error for InvalidUrlError {}
#[derive(Debug, Display)]
pub enum TtfbError {
#[display(fmt = "Invalid URL! {}", _0)]
InvalidUrl(InvalidUrlError),
#[display(fmt = "Can't resolve DNS! {}", _0)]
CantResolveDns(ResolveDnsError),
#[display(fmt = "Can't establish TCP-Connection! {}", _0)]
CantConnectTcp(io::Error),
#[display(fmt = "Can't establish TLS-Connection! {}", _0)]
CantConnectTls(native_tls::Error),
#[display(fmt = "Can't verify TLS-Connection! {}", _0)]
CantVerifyTls(HandshakeError<TcpStream>),
#[display(fmt = "Can't establish HTTP/1.1-Connection! {}", _0)]
CantConnectHttp(io::Error),
#[display(fmt = "There was a problem with the stream: {}", _0)]
OtherStreamError(io::Error),
}
impl Error for TtfbError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
TtfbError::InvalidUrl(err) => Some(err),
TtfbError::CantResolveDns(err) => Some(err),
TtfbError::CantConnectTls(err) => Some(err),
TtfbError::CantConnectTcp(err) => Some(err),
TtfbError::OtherStreamError(err) => Some(err),
TtfbError::CantVerifyTls(err) => Some(err),
TtfbError::CantConnectHttp(err) => Some(err),
}
}
}