fastcgi_client/conn.rs
1// Copyright 2022 jmjoy
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Connection mode definitions for FastCGI clients.
16//!
17//! This module defines the different connection modes that can be used
18//! with the FastCGI client: short connection and keep-alive modes.
19
20/// Trait defining the behavior of different connection modes.
21pub trait Mode {
22 /// Returns whether this mode supports keep-alive connections.
23 fn is_keep_alive() -> bool;
24}
25
26/// Short connection mode.
27///
28/// In this mode, the client establishes a new connection for each request
29/// and closes it after receiving the response.
30pub struct ShortConn;
31
32impl Mode for ShortConn {
33 fn is_keep_alive() -> bool {
34 false
35 }
36}
37
38/// Keep alive connection mode.
39///
40/// In this mode, the client maintains a persistent connection
41/// and can send multiple requests over the same connection.
42pub struct KeepAlive {}
43
44impl Mode for KeepAlive {
45 fn is_keep_alive() -> bool {
46 true
47 }
48}