rust_tcp_sever-0.1.8 has been yanked.
Rust TcpSever
A simple and lightweight crate for launching and using a server.
Reasons to choose Rust-TcpSever:
Contact with the developer.
Future of the library
The library will be updated as new proposals and ideas are received. If I no longer want to develop this project, I will write about it.
Usage example:
extern crate rust_tcp_sever;
pub use rust_tcp_sever::*;
fn main() {
TcpServer::set_http("HTTP/2.0");
TcpServer::set_map_code_page(vec![
(
String::from("404 NOT FOUND"),
Response::new_from_file("examples_rs/defpage.html", "text/html"),
)
]);
let server = TcpServer::new(Server::get_server("127.0.0.1:80"), ThreadPool::new(4));
Server::launch_range_port(server, 443..444);
}
struct Server;
impl SeverControl for Server {
#[inline]
fn match_methods(request: &Request, response: &mut Response) {
println!("{:#?}", request);
match request.metod.as_str() {
"GET" => Self::match_get(request, response),
"POST" => Self::match_post(request, response),
"PUT" => Self::match_put(request, response),
_ => {}
}
println!("{:#?}", response);
}
#[inline]
fn get_server<T: ToSocketAddrs>(ip_addr: T) -> TcpListener { TcpListener::bind(ip_addr).unwrap() }
}
impl Server {
#[inline]
fn match_get(request: &Request, response: &mut Response) {
match request.url.as_str() {
"/qwe" => response.html(
|resp| {
resp.echo(r#"<meta charset="utf-8">"#);
resp.echo(r#"<title>Cat Dark Net</title>"#);
},
|resp| {
resp.echo("<h1>123</h1>");
resp.echo("<h3>123</h3>");
resp.echo("<p>123</p>");
},
),
"/response" => {
response.set_file("examples_rs/webpage.html", "text/html");
response.cookie.add("net", "qwe");
response.cookie.delete("qwe");
}
"/giphy.webp" => response.set_file("examples_rs/giphy.webp", "image/webp"),
"/image.png" => response.set_file("examples_rs/image.png", "image/png"),
"/video.mp4" => response.set_file("examples_rs/video.mp4", "video/mp4"),
"/audio.mp3" => response.set_file("examples_rs/audio.mp3", "audio/mp3"),
"/favicon.ico" => response.set_file("examples_rs/image.png", "image/png"),
"/wer" => response.set_redirect("/response"),
"/sleep" => std::thread::sleep(std::time::Duration::from_secs(30)),
_ => {}
}
}
#[inline]
fn match_post(_request: &Request, _response: &mut Response) {}
#[inline]
fn match_put(_request: &Request, _response: &mut Response) {}
}
Author Support
SWIFT transfer:
Information on SWIFT transfer:
- Full name: Gakh Alexander Nikolaevich
- SWIFT-code Bank: TICSRUMM
- IBAM: RU9104452597440817810500116388926
License
This project is licensed under a Proprietary License.
Summary:
- By downloading the library, you automatically agree to the license.
- You can only change your copy of the project downloaded from GitHub.
- You can only download the library from GitHub or crates.io.
- It is prohibited to forward even an unmodified copy to other people.
- Copyright of this software remains with the author. All rights reserved.
- The author does not bear any responsibility for damage caused.