Coverage Report

Created: 2026-07-30 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/ureq-proto-0.6.0/src/close_reason.rs
Line
Count
Source
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)]
6
pub 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
35
impl CloseReason {
36
0
    pub(crate) fn explain(&self) -> &'static str {
37
0
        match self {
38
0
            CloseReason::ClientConnectionClose => "client sent Connection: close",
39
0
            CloseReason::ServerConnectionClose => "server sent Connection: close",
40
0
            CloseReason::Not100Continue => "non-100 response before body",
41
0
            CloseReason::ProtocolSwitch => "protocol switched via 101",
42
0
            CloseReason::CloseDelimitedBody => "response body is close delimited",
43
        }
44
0
    }
45
}