/// Produces the response for some content.
///
/// Assembles the response in a newly allocated buffer before sending.
/// The response will be sent to `sock`. It will have the status code
/// `status` which must be both the numerical code and the reason phrase.
/// The content type of the response will be set to `content_type`. The
/// content will be taken from content.
Produces the response for some content.
Assembles the response in a newly allocated buffer before sending.
The response will be sent to `sock`. It will have the status code
`status` which must be both the numerical code and the reason phrase.
The content type of the response will be set to `content_type`. The
content will be taken from content.
Produces the response for some content . Assembles the response in a newly allocated buffer before sending . The response will be sent to ` sock ` . It will have the status code ` status ` which must be both the numerical code and the reason phrase . The content type of the response will be set to ` content_type ` . The content will be taken from content .
fn from_content<T: AsRef<[u8]> + ?Sized>(
        sock: TcpStream,
        status: &'static str,
        content_type: &'static str,
        content: &T
    ) -> Self {
        let content = content.as_ref();
        let mut res = Vec::with_capacity(
            status.len() + content_type.len() + content.len()
            + 12 // for content length -- should be enough
            + 11 + 16 + 18 + 2 // Presumably, the compiler is smart enough ...
        ); 
        write!(&mut res, 
            "HTTP/1.1 {}\r\n\
             Content-Type: {}\r\n\
             Content-Length: {}\r\n\
             \r\n",
            status,
            content_type,
            content.len(),
        ).unwrap();
        res.extend_from_slice(content);
        Response::Vec(write_all(sock, res))
    }
fn from_content < T : AsRef < [ u8 ] > + ? Sized > ( sock : TcpStream , status : & ' static str , content_type : & ' static str , content : & T ) -> Self { let content = content . as_ref ( ) ; let mut res = Vec :: with_capacity ( status . len ( ) + content_type . len ( ) + content . len ( ) + 12 // for content length -- should be enough + 11 + 16 + 18 + 2 // Presumably, the compiler is smart enough ... ) ; write ! ( mut res " \r \n \
 \r \n \
 \r \n \
 \r \n " status content_type content len ( ) ) . unwrap ( ) ; res . extend_from_slice ( content ) ; Response :: Vec ( write_all ( sock , res ) ) }
Produces the response for some content.
Produces the response for some content .
sock
TcpStream
status
&'static str
content_type
&'static str
content
&T