├── .github └── workflows │ └── rust.yml ├── .gitignore ├── .idea ├── .gitignore ├── RustleWeb.iml ├── modules.xml └── vcs.xml ├── Cargo.lock ├── Cargo.toml ├── demo.png ├── index.html ├── readme.md └── src └── main.rs /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | name: Rust 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | - name: Build 20 | run: cargo build --verbose 21 | - name: Run tests 22 | run: cargo test --verbose 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/RustleWeb.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "RustleWeb" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "RustleWeb" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | 7 | 8 | [package.metadata] 9 | authors=["Mohammad Hasani"] 10 | 11 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohammadhasanii/RustleWeb/2fe01b2473a94130a5b9d0e4a74d905b0599799e/demo.png -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | RustleWeb 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |

18 | Rust Language 19 |

20 |

21 | A language empowering everyone 22 | to build reliable and efficient software 23 |

24 |
25 | 26 |
27 |
30 | 31 | 53 | 54 |
57 |
58 |
59 | 60 |
63 |
64 |
65 |
66 |
67 |
68 | 69 | 70 |

71 | Performance and Reliability and Productivity all in one programming language 72 | 73 |

74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # RustleWeb 2 | 3 | RustleWeb is a simple TCP server written in Rust. It listens on port 45000 for connections. 4 | No framework or tools are used in this program and all functions are written pure 5 | 6 | 7 | 8 | 9 | ## Demo 10 | 11 | This is a demo when served on 127.0.0.1:45000 12 | 13 | ![Logo](https://github.com/mohammadhasanii/RustleWeb/blob/master/demo.png) 14 | 15 | 16 | ## Installation 17 | 18 | To install RustleWeb, you will need to have the Rust compiler installed. Once you have Rust installed, you can install RustleWeb with the following command: 19 | 20 | ```bash 21 | cargo run 22 | ``` 23 | 24 | ## Usage 25 | 26 | ```javascript 27 | GET http://127.0.0.1:45000/ 28 | ``` 29 | 30 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | 2 | use std::{ 3 | fs, 4 | io::{prelude::*, BufReader}, 5 | net::{TcpListener, TcpStream}, 6 | }; 7 | 8 | fn handle_connection(mut stream:TcpStream) { 9 | 10 | let buf_reader = BufReader::new(&mut stream); 11 | let _http_request: Vec<_> = buf_reader 12 | .lines() 13 | .map(|result| result.unwrap()) 14 | .take_while(|line| !line.is_empty()) 15 | .collect(); 16 | 17 | let status_line = "HTTP/1.1 200 OK"; 18 | let contents = fs::read_to_string("index.html").unwrap(); 19 | let length = contents.len(); 20 | 21 | let response = 22 | format!("{status_line}\r\nContent-Length: {length}\r\n\r\n{contents}"); 23 | 24 | stream.write_all(response.as_bytes()).unwrap(); 25 | 26 | 27 | } 28 | fn main() { 29 | 30 | let listener=TcpListener::bind("127.0.0.1:45000").unwrap(); //loop for each tcp request 31 | for stream in listener.incoming() { 32 | let stream = stream.unwrap(); 33 | handle_connection(stream); 34 | } 35 | 36 | 37 | 38 | } 39 | --------------------------------------------------------------------------------