rustyphoenixrequest 1.6.1

This library provides methods to mock request API. This is the Rust equivalent of https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS2/network/PhoenixRequest
Documentation
/***************************************
	Auteur : Pierre Aubert
	Mail : pierre.aubert@lapp.in2p3.fr
	Licence : CeCILL-C
****************************************/

use crate::pmimetype::PMimeType;

#[derive(Debug, Default)]
pub struct PRequestParam {
	///Command of the request (i.e. GET)
	command: String,
	///Url of the request (i.e. /)
	url: String,
	///Protocol of the request (i.e. HTTP/1.1)
	protocol: String,
}

impl PRequestParam {
	///Set the command of the PRequestParam
	/// # Parameters
	/// - `command` : command of the request (i.e. GET)
	pub fn set_command(&mut self, command: &String) {
		self.command = command.to_string();
	}
	///Set the url of the PRequestParam
	/// # Parameters
	/// - `url` : url of the request (i.e. /)
	pub fn set_url(&mut self, url: &String) {
		self.url = url.to_string();
	}
	///Set the protocol of the PRequestParam
	/// # Parameters
	/// - `protocol` : protocol of the request (i.e. HTTP/1.1)
	pub fn set_protocol(&mut self, protocol: &String) {
		self.protocol = protocol.to_string();
	}
	///Get the url of the PRequestParam
	/// # Returns
	/// url of the request (i.e. /)
	pub fn get_url(&self) -> &String {
		&self.url
	}
	///Get the command of the PRequestParam
	/// # Returns
	/// command of the request (i.e. /)
	pub fn get_command(&self) -> &String {
		&self.command
	}
	///Get the protocol of the PRequestParam
	/// # Returns
	/// protocol of the request (i.e. /)
	pub fn get_protocol(&self) -> &String {
		&self.protocol
	}
}


#[derive(Debug, Default)]
pub struct PResponseParam {
	///Status of the response (i.e. HTTP/1.1 200 OK)
	pub status: String,
	///Type of the content string
	pub mimetype: PMimeType,
	///Content of the response (i.e. some html page)
	pub content: String,
}

impl PResponseParam {
	///Constructor of the PResponseParam
	/// # Parameters
	/// - `status` : status of the response (i.e. HTTP/1.1 200 OK)
	/// - `mimetype` : type of the content string
	/// - `content` : content of the response (i.e. some html page)
	pub fn new(status: String, mimetype: PMimeType, content: &String) -> Self{
		PResponseParam {
			status: status,
			mimetype: mimetype,
			content: content.to_owned()
		}
	}
	///Set the status of the PResponseParam
	/// # Parameters
	/// - `status` : status of the request (i.e. GET)
	pub fn set_status(&mut self, status: &String) {
		self.status = status.to_string();
	}
	///Set the content of the PResponseParam
	/// # Parameters
	/// - `content` : content of the response (i.e. GET)
	pub fn set_content(&mut self, content: &String) {
		self.content = content.to_string();
	}
	///Set the mime type of the response
	/// # Parameters
	/// - `mimetype` : type of the content of the response
	pub fn set_mime_type(&mut self, mimetype: &PMimeType){
		self.mimetype = *mimetype;
	}
}

pub trait PhoenixRequestStream {
	///Recieved a request from a client
	/// # Parameters
	/// - `request` : PRequestParam recievred from the client
	/// # Returns
	/// corresponding request
	fn recv_request(&mut self, request: &mut PRequestParam) -> bool;

	///Send response to the client
	/// # Returns
	/// corresponding request
	fn send_response(&mut self, response: &PResponseParam);
}

pub trait PhoenixRequestMockStream {
	///Set the record mode in the mock
	/// # Parameters
	/// - `is_mock_record` - true if the mock is in record mode
	fn set_is_record(&mut self, is_mock_record: bool);

	///Set the prefix of the current mock
	/// # Parameters
	/// - `prefix` - prefix of the current mock
	fn set_prefix(&mut self, prefix: &String);
}

pub trait PhoenixRequestServer {
	type Stream;
	///Initialise the Request server
	/// # Parameters
	/// - `hostname` : address of the server
	/// - `port` : port of the server
	/// # Returns
	/// initialised Request server
	fn new(hostname: &String, port: u16) -> Self;
	///Accept the connection and get a corresponding stream
	/// # Returns
	/// corresponding stream
	fn accept(&self) -> Self::Stream;
}

pub trait PhoenixRequestMockServer {
	///Set the record mode in the mock
	/// # Parameters
	/// - `is_mock_record` - true if the mock is in record mode
	fn set_is_record(&mut self, is_mock_record: bool);

	///Set the prefix of the current mock
	/// # Parameters
	/// - `prefix` - prefix of the current mock
	fn set_prefix(&mut self, prefix: &String);
}