ureq_proto/server/
send100.rs

1use http::{StatusCode, Version};
2
3use crate::util::Writer;
4use crate::Error;
5
6use super::state::{ProvideResponse, RecvBody, Send100};
7use super::{do_write_send_line, Reply};
8
9impl Reply<Send100> {
10    /// Sends a 100 Continue response and proceeds to receiving the body.
11    ///
12    /// This method sends an HTTP 100 Continue response to the client, indicating that
13    /// the server is willing to accept the request body. After sending the response,
14    /// it transitions to the RecvBody state to receive the request body.
15    ///
16    /// Returns a tuple with the number of bytes written to the output buffer and
17    /// the Reply in the RecvBody state.
18    ///
19    /// Returns an `Error::OutputOverflow` if the output buffer isn't large enough to
20    /// contain the 100 Continue status line.
21    pub fn accept(self, output: &mut [u8]) -> Result<(usize, Reply<RecvBody>), Error> {
22        let mut w = Writer::new(output);
23
24        let success = do_write_send_line((Version::HTTP_11, StatusCode::CONTINUE), &mut w, true);
25        if !success {
26            return Err(Error::OutputOverflow);
27        }
28
29        let output_used = w.len();
30
31        let flow = Reply::wrap(self.inner);
32
33        Ok((output_used, flow))
34    }
35
36    /// Rejects the 100 Continue request and proceeds to providing a response.
37    ///
38    /// This method rejects the client's "Expect: 100-continue" request and transitions
39    /// to the ProvideResponse state. The server should then provide an error response
40    /// (typically a 4xx or 5xx status code) to indicate why the request was rejected.
41    pub fn reject(mut self) -> Reply<ProvideResponse> {
42        self.inner.expect_100_reject = true;
43        Reply::wrap(self.inner)
44    }
45}