ureq_proto/close_reason.rs
1/// Reasons for closing an HTTP connection.
2///
3/// This enum represents the various reasons why an HTTP connection might need
4/// to be closed after a request/response cycle is complete.
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum CloseReason {
7 /// Client sent `connection: close`.
8 ClientConnectionClose,
9
10 /// Server sent `connection: close`.
11 ServerConnectionClose,
12
13 /// When doing expect-100 the server sent _some other response_.
14 ///
15 /// For expect-100, the only options for a server response are:
16 ///
17 /// * 100 continue, in which case we continue to send the body.
18 /// * do nothing, in which case we continue to send the body after a timeout.
19 /// * a 4xx or 5xx response indicating the server cannot receive the body.
20 Not100Continue,
21
22 /// Protocol upgrade via 101 Switching Protocols.
23 ///
24 /// The connection is still open but should NOT be returned to the pool
25 /// because it's now using a different protocol (e.g., WebSocket, HTTP/2).
26 ProtocolSwitch,
27
28 /// Response body is close delimited.
29 ///
30 /// We do not know how much body data to receive. The socket will be closed
31 /// when it's done. This is HTTP/1.0 semantics.
32 CloseDelimitedBody,
33}
34
35impl CloseReason {
36 pub(crate) fn explain(&self) -> &'static str {
37 match self {
38 CloseReason::ClientConnectionClose => "client sent Connection: close",
39 CloseReason::ServerConnectionClose => "server sent Connection: close",
40 CloseReason::Not100Continue => "non-100 response before body",
41 CloseReason::ProtocolSwitch => "protocol switched via 101",
42 CloseReason::CloseDelimitedBody => "response body is close delimited",
43 }
44 }
45}