simbld_http/responses/
client.rs

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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
use crate::helpers::{from_u16_helper::FromU16, to_u16_helper::ToU16};
use num_enum::{IntoPrimitive, TryFromPrimitive};
use strum_macros::{Display, EnumIter, EnumProperty};
use strum::EnumProperty;

#[derive(Display, IntoPrimitive, TryFromPrimitive, EnumProperty, EnumIter, Debug, Copy, Clone)]
#[repr(u16)]

pub enum ResponsesClientCodes {
  #[strum(props(
    Description = "The server cannot process the request due to malformed syntax or invalid parameters in the client request"
  ))]
  BadRequest = 400,
  #[strum(props(
    Description = "The client must authenticate itself to get the requested resource, typically a 401 Unauthorized response"
  ))]
  Unauthorized = 401,
  #[strum(props(
    Description = "Payment is required to access the requested resource, though this is not widely used in practice"
  ))]
  PaymentRequired = 402,
  #[strum(props(
    Description = "The server understands the request but refuses to authorize it, indicating insufficient permissions"
  ))]
  Forbidden = 403,
  #[strum(props(
    Description = "The server cannot find the requested resource, indicating a non-existent or inaccessible URI"
  ))]
  NotFound = 404,
  #[strum(props(
    Description = "The HTTP method used in the request is not supported for the target resource"
  ))]
  MethodNotAllowed = 405,
  #[strum(props(
    Description = "The requested resource cannot be provided in a format acceptable according to the request's Accept headers"
  ))]
  NotAcceptable = 406,
  #[strum(props(
    Description = "The client must authenticate with a proxy server before accessing the resource"
  ))]
  ProxyAuthenticationRequired = 407,
  #[strum(props(
    Description = "The server timed out while waiting for the request from the client. This status code is used to inform the client that the server timed out."
  ))]
  RequestTimeout = 408,
  #[strum(props(
    Description = "The request could not be completed due to a conflict with the current state of the target resource"
  ))]
  Conflict = 409,
  #[strum(props(
    Description = "The requested resource is no longer available and has been permanently removed from the server and will not be available again"
  ))]
  Gone = 410,
  #[strum(props(Description = "The request does not include the required Content-Length header"))]
  LengthRequired = 411,
  #[strum(props(
    Description = "One or more conditions in the request headers are not met by the server"
  ))]
  PreconditionFailed = 412,
  #[strum(props(
    Description = "The size of the request payload exceeds the server's capacity or configuration limits"
  ))]
  PayloadTooLarge = 413,
  #[strum(props(
    Description = "The URI of the request is too long for the server to process. This status code is used to inform the client that the request URI is too long"
  ))]
  RequestUriTooLong = 414,
  #[strum(props(
    Description = "The media type of the request payload is not supported by the server or target resource"
  ))]
  UnsupportedMediaType = 415,
  #[strum(props(
    Description = "The client requested a range that is not satisfiable for the target resource"
  ))]
  RequestedRangeUnsatisfiable = 416,
  #[strum(props(
    Description = "The server cannot meet the requirements specified in the Expect header field of the request"
  ))]
  ExpectationFailed = 417,
  #[strum(props(
    Description = "A playful response indicating the server is a teapot and cannot brew coffee (RFC 2324)"
  ))]
  ImATeapot = 418,
  #[strum(props(
    Description = "Issued by Laravel when a CSRF token is missing or expired, unofficial"
  ))]
  PageExpired = 419,
  #[strum(props(
    Description = "The method specified in the request is known by the server but cannot be processed due to a failure in the server's implementation, Issued by Spring when a method has failed. Now deprecated and reserved for backward compatibility, unofficial"
  ))]
  MethodFailure = 420,
  #[strum(props(
    Description = "Used by Twitter to indicate that the client has sent too many requests in a given amount of time, unofficial"
  ))]
  MisdirectedRequest = 421,
  #[strum(props(
    Description = "The request is well-formed but cannot be processed due to semantic errors, commonly used in APIs, use in WebDav RFC 4918"
  ))]
  UnprocessableEntity = 422,
  #[strum(props(
    Description = "The resource is locked and cannot be accessed or modified, typically used in WebDav RFC 4918"
  ))]
  LockedTemporarilyUnavailable = 423,
  #[strum(props(
    Description = "The request failed because it depended on another operation that failed, often used in WebDav RFC 4918"
  ))]
  FailedDependency = 424,
  #[strum(props(
    Description = "The server is unwilling to process the request because it might be replayed"
  ))]
  TooEarly = 425, // Only for Firefox
  #[strum(props(
    Description = "The client must upgrade to a different protocol to continue with the request"
  ))]
  UpgradeRequired = 426,
  #[strum(props(
    Description = "The server requires the request to include specific preconditions to proceed"
  ))]
  PreconditionRequired = 428,
  #[strum(props(
    Description = "The resource is rate-limited and the client has sent too many requests in the allotted time"
  ))]
  TooManyRequests = 429,
  #[strum(props(
    Description = "Issued by Shopify to indicate a rate-limit effect. This is used instead of 429, unofficial"
  ))]
  RequestHeaderFieldsTooLarge = 430,
  #[strum(props(
    Description = "Authentication is required to access the requested resource, typically in web applications"
  ))]
  LoginRequired = 432,
  #[strum(props(
    Description = "The request was rejected due to an issue with the origin server or client IP"
  ))]
  OriginError = 433,
  #[strum(props(
    Description = "The request was rejected due to an issue with the destination server or target configuration"
  ))]
  DestinationError = 434,
  #[strum(props(
    Description = "The size of the requested resource or payload exceeds the allowable limit for the server"
  ))]
  TooLarge = 435,
  #[strum(props(
    Description = "An error occurred due to an invalid or untrusted SSL certificate"
  ))]
  SSLCertificateError = 436,
  #[strum(props(
    Description = "The server requires a valid SSL certificate for the connection to proceed securely"
  ))]
  SSLCertificateRequired = 437,
  #[strum(props(
    Description = "The client did not provide an SSL certificate required for secure communication"
  ))]
  NoCertificate = 438,
  #[strum(props(
    Description = "The client session timed out and must log in again, iis, unofficial"
  ))]
  LoginTimeout = 440,
  #[strum(props(
    Description = "The client has exceeded the allocated data quota for the requested operation"
  ))]
  OverDataQuota = 441,
  #[strum(props(
    Description = "The server closed the connection without sending any response, often used in scenarios where the server chooses to silently drop the request, nginx, unofficial"
  ))]
  NoResponse = 444,
  #[strum(props(
    Description = "The user has not provided the required information, iis, unofficial"
  ))]
  RetryWith = 449,
  #[strum(props(
    Description = "Issued by Microsoft when Windows Parental Controls are turned on and a resource is blocked, unofficial"
  ))]
  BlockedByWindowsParentalControls = 450,
  #[strum(props(
    Description = "The server is denying access to the resource due to legal reasons, such as censorship or compliance with local laws"
  ))]
  UnavailableForLegalReasons = 451,
  #[strum(props(
    Description = "The server is unable to process the request because it contains too many recipients"
  ))]
  TooManyRecipients = 452,
  #[strum(props(
    Description = "The method specified in the request is not valid for the current state of the resource or server"
  ))]
  MethodNotValidInThisState = 455,
  #[strum(props(
    Description = "The server encountered a critical error that prevents it from continuing to process the request"
  ))]
  UnrecoverableError = 456,
  #[strum(props(
    Description = "The client closed the connection before the server was able to send a response, often due to a timeout or network interruption"
  ))]
  ClientClosedConnexionPrematurely = 460,
  #[strum(props(
    Description = "The server rejected the request due to an excessive number of forwarded IP addresses in the request headers, potentially indicating a misconfiguration or a security concern"
  ))]
  TooManyForwardedIPAddresses = 463,
  #[strum(props(
    Description = "An internet security policy violation or configuration issue occurred, often related to SSL/TLS settings, certificates, or protocol mismatches"
  ))]
  InternetSecurityError = 467,
  #[strum(props(
    Description = "The server is temporarily unavailable, usually due to maintenance or overload"
  ))]
  TemporaryUnavailable = 480,
  #[strum(props(
    Description = "The server is unable to process the request because the headers are too large, often due to a misconfiguration or an attack, nginx, unofficial"
  ))]
  RequestHeaderTooLarge = 494,
  #[strum(props(
    Description = "The SSL certificate presented by the client is invalid or cannot be verified by the server, preventing a secure connection from being established, nginx, unofficial"
  ))]
  CertError = 495,
  #[strum(props(
    Description = "A required client certificate wasn't provided, preventing the server from establishing a secure connection, nginx, unofficial"
  ))]
  NoCert = 496,
  #[strum(props(
    Description = "The client sent an unencrypted HTTP request to a server that requires HTTPS, and the server is redirecting the client to the HTTPS version of the resource, nginx, unofficial"
  ))]
  HTTPToHTTPS = 497,
  #[strum(props(
    Description = "The provided token is invalid, expired, or malformed, and cannot be used for authentication or authorization, Issued by ArcGIS for Server, unofficial"
  ))]
  InvalidToken = 498,
  #[strum(props(
    Description = "The client closed the connection before the server could provide a response, often due to client timeout or network interruption, nginx, unofficial"
  ))]
  ClientClosedRequest = 499,
}

impl ToU16 for ResponsesClientCodes {
  fn to_u16(self) -> u16 {
    self.into() // Conversion`Into<u16>`
  }
}

impl FromU16 for ResponsesClientCodes {
  fn from_u16(code: u16) -> Option<Self> {
    Self::try_from(code).ok() // Conversion`TryFrom<u16>`
  }
}

impl Into<(u16, &'static str)> for ResponsesClientCodes {
  fn into(self) -> (u16, &'static str) {
    let code: u16 = self.to_u16();
    let description = self.get_str("Description").unwrap_or("No description");
    (code, description) // Tuple
  }
}