In progress, primarily used for learning Rust programming.
This project is based on the programming exercise Building a multithreaded web server from the book The Rust Programming Language (no starch press 2018) and inspired by the Aomebo Web Framework for PHP.
rust-fmt
on all rust filescargo check
and cargo test
to ensure validitycargo run --example static localhost 8888 10 index.htm ./html/ 404.htm 1024
Parameters are: * TCP Hostname * TCP Port * Limit of workers * HTTP directory index file * HTTP web-server file-system root * HTTP file not found file * Maximum TCP request size
``` rust extern crate milstianinternetframework; use milstianinternetframework::{Application, Config};
fn main() { let config = Config::fromenv().expect("Failed to get configuration from environment"); Application::new(config).tcphttpwithlegacy_responders(); } ```
``` rust extern crate milstianinternetframework;
use std::collections::HashMap; use std::net::SocketAddr; use milstianinternetframework::request; use milstianinternetframework::response; use milstianinternetframework::response::tcp::http::ResponderInterface; use milstianinternetframework::{Application, Config};
pub struct Responder {
pub route: Option
impl Responder { pub fn new() -> Responder { Responder { route: None } } }
impl ResponderInterface for Responder { fn matches( &mut self, requestmessage: &request::Message, _application: &Application, _socket: &SocketAddr, _overflowbytes: &u8, ) -> bool { match requestmessage.requestline.query_arguments.get("test") { Some(value) => { self.route = Some(value.clone()); return true; } None => { return false; } } }
fn respond(
&self,
request_message: &request::Message,
_application: &Application,
_socket: &SocketAddr,
_overflow_bytes: &u8,
) -> Result<Vec<u8>, String> {
if let Some(route) = &self.route {
let protocol =
request::Message::get_protocol_text(&request_message.request_line.protocol);
let mut headers: HashMap<String, String> = HashMap::new();
headers.insert("Content-Type".to_string(), "text/plain".to_string());
return Ok(response::Message::new(
protocol.to_string(),
"200 OK".to_string(),
headers,
format!("Was here: {}", route).as_bytes().to_vec(),
).to_bytes());
} else {
Err("No result".to_string())
}
}
}
fn main() { let config = Config::fromenv().expect("Failed to get configuration from environment"); Application::new(config).tcphttpwithlegacyandcustom_responders(Box::new(Responder::new())); } ```
This project is under the GPLv3 license