pub fn build_headers(
		config: &HttpConfig,
		found: bool,
		found_404_content: bool,
		keep_alive: bool,
		additional_headers: Vec<(String, String)>,
		redirect: Option<String>,
		buf: &mut [u8],
	) -> Result<usize, Error> {
		let server_bytes = config.server_name.as_bytes();

		let transfer_encoding_bytes = if keep_alive {
			CHUNKED_ENCODING
		} else if !found && !found_404_content {
			NOT_FOUND_NO_CONTENT
		} else {
			FOUND_NO_KEEP_ALIVE
		};

		let mut itt = 0;
		if redirect.is_some() {
			let redir_str = format!(
				"HTTP/1.1 301 Moved Permanently\r\nLocation: {}\r\n",
				redirect.as_ref().unwrap_or(&"".to_string())
			);
			let redir_bytes = redir_str.as_bytes();
			itt = Self::clone_in_bytes(redir_bytes, buf, itt, redir_bytes.len())?;
		} else if found {
			itt = Self::clone_in_bytes(FOUND_BYTES, buf, itt, FOUND_BYTES.len())?;
		} else {
			itt = Self::clone_in_bytes(NOT_FOUND_BYTES, buf, itt, NOT_FOUND_BYTES.len())?;
		}

		itt = Self::build_date(buf, itt)?;
		itt = if additional_headers.len() > 0 {
			let mut additional_headers_formatted = String::new();
			for header in additional_headers {
				additional_headers_formatted = format!(
					"{}{}: {}\r\n",
					additional_headers_formatted, header.0, header.1,
				);
			}
			let additional_headers_formatted_bytes = additional_headers_formatted.as_bytes();
			Self::clone_in_bytes(
				additional_headers_formatted_bytes,
				buf,
				itt,
				additional_headers_formatted_bytes.len(),
			)?
		} else {
			itt
		};
		itt = Self::clone_in_bytes(SERVER_PRE, buf, itt, SERVER_PRE.len())?;
		itt = Self::clone_in_bytes(server_bytes, buf, itt, server_bytes.len())?;
		itt = Self::clone_in_bytes(SEPARATOR_BYTES, buf, itt, SEPARATOR_BYTES.len())?;
		itt = Self::clone_in_bytes(
			transfer_encoding_bytes,
			buf,
			itt,
			transfer_encoding_bytes.len(),
		)?;
		itt = Self::clone_in_bytes(SEPARATOR_BYTES, buf, itt, SEPARATOR_BYTES.len())?;
		itt = if found || found_404_content {
			itt
		} else if keep_alive {
			let not_found_message =
				format!("{:X}\r\n{}\r\n0\r\n\r\n", RESPONSE_404.len(), RESPONSE_404);
			let not_found_message_bytes = not_found_message.as_bytes();
			Self::clone_in_bytes(
				not_found_message_bytes,
				buf,
				itt,
				not_found_message_bytes.len(),
			)?
		} else {
			let not_found_message = format!("{}\r\n", RESPONSE_404);
			let not_found_message_bytes = not_found_message.as_bytes();
			Self::clone_in_bytes(
				not_found_message_bytes,
				buf,
				itt,
				not_found_message_bytes.len(),
			)?
		};
		Ok(itt)
	}
/// Build (but do not write) headers based on specified parameters.
/// * `config` - The [`HttpConfig`] associated with this connection.
/// * `found` - Whether or not this file was found.
/// * `keep-alive` - Whether or not to keep the connection alive after this response is sent.
/// * `additional_headers` - Additional headers to send with this response.
/// * `redirect` - Optional redirect for this request.
/// * `buf` - The buffer to write the response into. Note: the caller is responsible for
/// * ensuring the capacity of this buffer is sufficient.
Build (but do not write) headers based on specified parameters.
`config` - The [`HttpConfig`] associated with this connection.
`found` - Whether or not this file was found.
`keep-alive` - Whether or not to keep the connection alive after this response is sent.
`additional_headers` - Additional headers to send with this response.
`redirect` - Optional redirect for this request.
`buf` - The buffer to write the response into. Note: the caller is responsible for
ensuring the capacity of this buffer is sufficient.
Build ( but do not write ) headers based on specified parameters . ` config ` - The [ ` HttpConfig ` ] associated with this connection . ` found ` - Whether or not this file was found . ` keep - alive ` - Whether or not to keep the connection alive after this response is sent . ` additional_headers ` - Additional headers to send with this response . ` redirect ` - Optional redirect for this request . ` buf ` - The buffer to write the response into . Note : the caller is responsible for ensuring the capacity of this buffer is sufficient .
pub fn build_headers(
		config: &HttpConfig,
		found: bool,
		found_404_content: bool,
		keep_alive: bool,
		additional_headers: Vec<(String, String)>,
		redirect: Option<String>,
		buf: &mut [u8],
	) -> Result<usize, Error> {
		let server_bytes = config.server_name.as_bytes();
		let transfer_encoding_bytes = if keep_alive {
			CHUNKED_ENCODING
		} else if !found && !found_404_content {
			NOT_FOUND_NO_CONTENT
		} else {
			FOUND_NO_KEEP_ALIVE
		};
		let mut itt = 0;
		if redirect.is_some() {
			let redir_str = format!(
				"HTTP/1.1 301 Moved Permanently\r\nLocation: {}\r\n",
				redirect.as_ref().unwrap_or(&"".to_string())
			);
			let redir_bytes = redir_str.as_bytes();
			itt = Self::clone_in_bytes(redir_bytes, buf, itt, redir_bytes.len())?;
		} else if found {
			itt = Self::clone_in_bytes(FOUND_BYTES, buf, itt, FOUND_BYTES.len())?;
		} else {
			itt = Self::clone_in_bytes(NOT_FOUND_BYTES, buf, itt, NOT_FOUND_BYTES.len())?;
		}
		itt = Self::build_date(buf, itt)?;
		itt = if additional_headers.len() > 0 {
			let mut additional_headers_formatted = String::new();
			for header in additional_headers {
				additional_headers_formatted = format!(
					"{}{}: {}\r\n",
					additional_headers_formatted, header.0, header.1,
				);
			}
			let additional_headers_formatted_bytes = additional_headers_formatted.as_bytes();
			Self::clone_in_bytes(
				additional_headers_formatted_bytes,
				buf,
				itt,
				additional_headers_formatted_bytes.len(),
			)?
		} else {
			itt
		};
		itt = Self::clone_in_bytes(SERVER_PRE, buf, itt, SERVER_PRE.len())?;
		itt = Self::clone_in_bytes(server_bytes, buf, itt, server_bytes.len())?;
		itt = Self::clone_in_bytes(SEPARATOR_BYTES, buf, itt, SEPARATOR_BYTES.len())?;
		itt = Self::clone_in_bytes(
			transfer_encoding_bytes,
			buf,
			itt,
			transfer_encoding_bytes.len(),
		)?;
		itt = Self::clone_in_bytes(SEPARATOR_BYTES, buf, itt, SEPARATOR_BYTES.len())?;
		itt = if found || found_404_content {
			itt
		} else if keep_alive {
			let not_found_message =
				format!("{:X}\r\n{}\r\n0\r\n\r\n", RESPONSE_404.len(), RESPONSE_404);
			let not_found_message_bytes = not_found_message.as_bytes();
			Self::clone_in_bytes(
				not_found_message_bytes,
				buf,
				itt,
				not_found_message_bytes.len(),
			)?
		} else {
			let not_found_message = format!("{}\r\n", RESPONSE_404);
			let not_found_message_bytes = not_found_message.as_bytes();
			Self::clone_in_bytes(
				not_found_message_bytes,
				buf,
				itt,
				not_found_message_bytes.len(),
			)?
		};
		Ok(itt)
	}
pub fn build_headers ( config : & HttpConfig , found : bool , found_404_content : bool , keep_alive : bool , additional_headers : Vec < ( String , String ) > , redirect : Option < String > , buf : & mut [ u8 ] , ) -> Result < usize , Error > { let server_bytes = config . server_name . as_bytes ( ) ; let transfer_encoding_bytes = if keep_alive { CHUNKED_ENCODING } else if ! found && ! found_404_content { NOT_FOUND_NO_CONTENT } else { FOUND_NO_KEEP_ALIVE } ; let mut itt = 0 ; if redirect . is_some ( ) { let redir_str = format ! ( " \r \n \r \n " redirect as_ref ( ) unwrap_or ( " " to_string ( ) ) ) ; let redir_bytes = redir_str . as_bytes ( ) ; itt = Self :: clone_in_bytes ( redir_bytes , buf , itt , redir_bytes . len ( ) ) ? ; } else if found { itt = Self :: clone_in_bytes ( FOUND_BYTES , buf , itt , FOUND_BYTES . len ( ) ) ? ; } else { itt = Self :: clone_in_bytes ( NOT_FOUND_BYTES , buf , itt , NOT_FOUND_BYTES . len ( ) ) ? ; } itt = Self :: build_date ( buf , itt ) ? ; itt = if additional_headers . len ( ) > 0 { let mut additional_headers_formatted = String :: new ( ) ; for header in additional_headers { additional_headers_formatted = format ! ( " \r \n " additional_headers_formatted header 0 header 1 ) ; } let additional_headers_formatted_bytes = additional_headers_formatted . as_bytes ( ) ; Self :: clone_in_bytes ( additional_headers_formatted_bytes , buf , itt , additional_headers_formatted_bytes . len ( ) , ) ? } else { itt } ; itt = Self :: clone_in_bytes ( SERVER_PRE , buf , itt , SERVER_PRE . len ( ) ) ? ; itt = Self :: clone_in_bytes ( server_bytes , buf , itt , server_bytes . len ( ) ) ? ; itt = Self :: clone_in_bytes ( SEPARATOR_BYTES , buf , itt , SEPARATOR_BYTES . len ( ) ) ? ; itt = Self :: clone_in_bytes ( transfer_encoding_bytes , buf , itt , transfer_encoding_bytes . len ( ) , ) ? ; itt = Self :: clone_in_bytes ( SEPARATOR_BYTES , buf , itt , SEPARATOR_BYTES . len ( ) ) ? ; itt = if found || found_404_content { itt } else if keep_alive { let not_found_message = format ! ( " \r \n \r \n \r \n \r \n " RESPONSE_404 len ( ) RESPONSE_404 ) ; let not_found_message_bytes = not_found_message . as_bytes ( ) ; Self :: clone_in_bytes ( not_found_message_bytes , buf , itt , not_found_message_bytes . len ( ) , ) ? } else { let not_found_message = format ! ( " \r \n " RESPONSE_404 ) ; let not_found_message_bytes = not_found_message . as_bytes ( ) ; Self :: clone_in_bytes ( not_found_message_bytes , buf , itt , not_found_message_bytes . len ( ) , ) ? } ; Ok ( itt ) }
Build (but do not write) headers based on specified parameters.
Build ( but do not write ) headers based on specified parameters .
config
&HttpConfig
found
bool
found_404_content
bool
keep_alive
bool
additional_headers
Vec<(String, String)>
redirect
Option<String>
buf
&mut [u8]
config
&HttpConfig
found
bool
found_404_content
bool
keep_alive
bool
additional_headers
Vec<(String, String)>
redirect
Option<String>
buf
&mut [u8]