fastcgi_connect/request.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//! FastCGI request structure and builders.
16//!
17//! This module provides the `Request` struct that encapsulates
18//! the parameters and stdin data for a FastCGI request.
19
20use crate::Params;
21
22#[cfg(feature = "smol")]
23use smol::io::AsyncRead;
24#[cfg(feature = "tokio")]
25use tokio::io::AsyncRead;
26
27/// FastCGI request containing parameters and stdin data.
28///
29/// This structure represents a complete FastCGI request with all necessary
30/// parameters and an optional stdin stream for request body data.
31pub struct Request<'a, I: AsyncRead + Unpin> {
32 pub(crate) params: Params<'a>,
33 pub(crate) stdin: I,
34}
35
36impl<'a, I: AsyncRead + Unpin> Request<'a, I> {
37 /// Creates a new FastCGI request with the given parameters and stdin.
38 ///
39 /// # Arguments
40 ///
41 /// * `params` - The FastCGI parameters
42 /// * `stdin` - The stdin stream for request body data
43 pub fn new(params: Params<'a>, stdin: I) -> Self {
44 Self { params, stdin }
45 }
46
47 /// Returns a reference to the request parameters.
48 pub fn params(&self) -> &Params<'a> {
49 &self.params
50 }
51
52 /// Returns a mutable reference to the request parameters.
53 pub fn params_mut(&mut self) -> &mut Params<'a> {
54 &mut self.params
55 }
56
57 /// Returns a reference to the stdin stream.
58 pub fn stdin(&self) -> &I {
59 &self.stdin
60 }
61
62 /// Returns a mutable reference to the stdin stream.
63 pub fn stdin_mut(&mut self) -> &mut I {
64 &mut self.stdin
65 }
66}