-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
2,356 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
[package] | ||
name = "rust-web-server" | ||
version = "9.0.0" | ||
version = "10.0.0" | ||
authors = ["Bohdan Tsap <[email protected]>"] | ||
repository = "https://github.com/bohdaq/rust-web-framework/" | ||
description = "Collection of utility functions used to build Rust Web and TLS Server. Can be useful while developing HTTP related functionality" | ||
edition = "2021" | ||
license = "MIT OR Apache-2.0 OR ISC OR LGPL-3.0-or-later OR CC-BY-4.0" | ||
categories = ["web-programming", "web-programming::http-client", "web-programming::http-server", "parsing", "network-programming"] | ||
keywords = ["HTTP", "server", "request", "response", "header"] | ||
rust-version = "1.66" | ||
rust-version = "1.67" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
file-ext = "9.0.3" | ||
file-ext = "9.0.3" | ||
url-search-params = "9.0.0" | ||
url-build-parse = "9.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
## Developer environment setup on Ubuntu 22.04.1 LTS | ||
|
||
Assumption is you have fresh installation of Ubuntu 22.04.1 LTS. | ||
|
||
### 1. Install Rust | ||
> sudo apt install curl | ||
> curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh | ||
Press Enter to proceed with default installation | ||
|
||
> source ~/.cargo/env | ||
> rustc -V | ||
### 2. Setup git | ||
|
||
> cd ~ | ||
> mkdir git | ||
> cd git | ||
> sudo apt install git | ||
### 3. Clone repository | ||
|
||
> git clone https://github.com/bohdaq/rust-web-server.git | ||
> cd rust-web-server | ||
### 4. Install required build tools | ||
|
||
> sudo apt install build-essential | ||
### 5. Run tests | ||
|
||
> cargo test | ||
If you see failed test, rerun previous command | ||
|
||
### 6. Start server | ||
|
||
> cargo run | ||
At this point, server is started on loopback device (ip 127.0.0.1) | ||
and is not accessible from the network. | ||
|
||
Try to open url in the browser | ||
Press Ctrl + C (CMD + C) to stop the server | ||
|
||
### 7. Allow requests from network | ||
|
||
> sudo ufw disable | ||
This will disable firewall and enable requests to the server from your network | ||
|
||
### 8. Start server on network connected device | ||
|
||
> sudo apt install net-tools | ||
> ifconfig | ||
Find your ip and restart the server | ||
|
||
> cargo run -- --ip=IP_FROM_IFCONFIG | ||
Check again url in the browser |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
ISC License (ISC) | ||
Copyright (c) 2022, Bohdan Tsap <[email protected]> | ||
Copyright (c) 2023, Bohdan Tsap <[email protected]> | ||
|
||
Permission to use, copy, modify, and/or distribute this software for | ||
any purpose with or without fee is hereby granted, provided that the | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::collections::HashMap; | ||
use crate::mime_type::MimeType; | ||
use crate::range::{ContentRange, Range}; | ||
use crate::request::{METHOD, Request}; | ||
use crate::response::{Response, STATUS_CODE_REASON_PHRASE}; | ||
use crate::symbol::SYMBOL; | ||
|
||
pub struct FormGetMethodController; | ||
|
||
impl FormGetMethodController { | ||
|
||
pub fn is_matching_request(request: &Request) -> bool { | ||
let boxed_path = request.get_uri_path(); | ||
if boxed_path.is_err() { | ||
let message = format!("unable to get path {}", boxed_path.err().unwrap()); | ||
eprintln!("{}", message); | ||
return false | ||
} | ||
|
||
let path = boxed_path.unwrap(); | ||
path == "/form-get-method" && request.method == METHOD.get | ||
|
||
} | ||
|
||
pub fn process_request(_request: &Request, mut response: Response) -> Response { | ||
response.status_code = *STATUS_CODE_REASON_PHRASE.n200_ok.status_code; | ||
response.reason_phrase = STATUS_CODE_REASON_PHRASE.n200_ok.reason_phrase.to_string(); | ||
|
||
// here is the form data, as an example here it is printed in the response body | ||
let boxed_query_option = _request.get_uri_query(); | ||
if boxed_query_option.is_err() { | ||
let error_message = boxed_query_option.clone().err().unwrap().to_string(); | ||
eprintln!("unable to extract query from url: {}", error_message) | ||
} | ||
let query_option = boxed_query_option.unwrap(); | ||
if query_option.is_some() { | ||
let form: HashMap<String, String> = query_option.unwrap(); | ||
|
||
|
||
let mut formatted_list : Vec<String> = vec![]; | ||
for (key, value) in form.into_iter() { | ||
let formatted_output = format!("{} is {}{}", key, value, SYMBOL.new_line_carriage_return); | ||
formatted_list.push(formatted_output); | ||
} | ||
|
||
let response_body = formatted_list.join(SYMBOL.empty_string); | ||
response.content_range_list = vec![ | ||
ContentRange{ | ||
unit: Range::BYTES.to_string(), | ||
range: Range { start: 0, end: response_body.len() as u64 }, | ||
size: response_body.len().to_string(), | ||
body: Vec::from(response_body.as_bytes()), | ||
content_type: MimeType::TEXT_PLAIN.to_string(), | ||
} | ||
]; | ||
} | ||
|
||
response | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod url_encoded_enctype_post_method; | ||
pub mod get_method; | ||
pub mod multipart_enctype_post_method; |
Oops, something went wrong.