Skip to content

Commit

Permalink
10.0.0 RC 1
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdaq committed Feb 15, 2023
1 parent 921c0c3 commit bda28a1
Show file tree
Hide file tree
Showing 45 changed files with 2,356 additions and 81 deletions.
8 changes: 5 additions & 3 deletions Cargo.toml
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"
68 changes: 68 additions & 0 deletions DEVELOPER/UBUNTU_LTS_DEVELOPER_SETUP.md
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.
2 changes: 1 addition & 1 deletion LICENSE-ISC → LICENSE/LICENSE-ISC
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
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion LICENSE-MIT → LICENSE/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Copyright (c) 2022 Bohdan Tsap
Copyright (c) 2023 Bohdan Tsap

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
<head>
<meta charset="UTF-8">
<title>Rust Web Server</title>
<link rel="stylesheet" href="/static/style.css">
<link rel="icon" href="/favicon.svg">
</head>
<body>
Hello world!
<ul>
<li><a href="/static/content.png">image</a></li>
<li><a href="/static/form.html">form</a></li>
<li><a href="/static/file.html">file</a></li>
<li><a href="/404">not found resource</a></li>
</ul>
</body>
Expand Down
102 changes: 78 additions & 24 deletions src/app/controller/favicon/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions src/app/controller/favicon/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use file_ext::FileExt;

use crate::mime_type::MimeType;
use crate::range::Range;
use crate::request::Request;
Expand All @@ -7,7 +8,7 @@ use crate::response::{Response, STATUS_CODE_REASON_PHRASE};
pub struct FaviconController;

impl FaviconController {
pub const STYLE_FILEPATH: &'static str = "favicon.svg";
pub const FAVICON_FILEPATH: &'static str = "favicon.svg";

pub fn is_matching_request(request: &Request) -> bool {
request.request_uri == "/favicon.svg"
Expand All @@ -18,9 +19,9 @@ impl FaviconController {
response.reason_phrase = STATUS_CODE_REASON_PHRASE.n200_ok.reason_phrase.to_string();


if FileExt::does_file_exist(FaviconController::STYLE_FILEPATH) {
if FileExt::does_file_exist(FaviconController::FAVICON_FILEPATH) {
let boxed_content_range =
Range::get_content_range_of_a_file(FaviconController::STYLE_FILEPATH);
Range::get_content_range_of_a_file(FaviconController::FAVICON_FILEPATH);

if boxed_content_range.is_ok() {
let content_range = boxed_content_range.unwrap();
Expand Down
60 changes: 60 additions & 0 deletions src/app/controller/form/get_method/mod.rs
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
}
}
3 changes: 3 additions & 0 deletions src/app/controller/form/mod.rs
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;
Loading

0 comments on commit bda28a1

Please sign in to comment.