Code Monkey home page Code Monkey logo

tondikwebserver's Introduction

Tondík Web Server

This Web Server was created as project for subject "Programming in C++" at VSB-TUO University

Milestone to the half of semester

  • HTTP Request parsing
  • Sending HTTP response
  • Completly working "dev" server
  • CMD line arguments: --dev, --host, --port
  • Serving multiple users at once (multithreading)

CMD Line

> ./main --help
Tondík Web Server

Argument types:
 --name=value
 -name value

Argument list:
 --help - shows this help
Dev mode:
 --dev - start server in dev mode
 --host - start dev server on 0.0.0.0 interface
 --port=8080 - start dev server on specific port
 --path=/path/to/folder - server files in specified folder
Server mode:
 --path=/etc/tondik - path to config folder

Modes

Dev mode (Fully implemented)

Used to serve only one folder. By default started on 127.0.0.1 on port 8080 and it will be serving ./ folder.

Parameters

  • --dev - start dev mode
  • --host - start on 0.0.0.0
  • --port=1234 - change port
  • --path=/path/to/folder - change folder

Server mode (Fully implemented)

Used to serve multiple folders based on domains/subdomains/hostnames.

Start

  • On default port 80:
sudo ./main

Port can by changed in config file, default ./main.ini

./main --path=/path/to/config/folder

Config file specifications (Based on INI)

  • key=value - set value to key
  • ;comment - single line comments
  • [section] - section, keys under this section will be: section.key, section will be ended when another section starts
  • array[]=value - add value to array
  • if something is before comment, then it isn't threated as comment, so: mime_types[]=test,text/plain; charset=UTF-8 will be treated as new item to mime_type array with value "test,text/plain; charset=UTF-8"

Main config file

port=80
;directory, where domain configs will be located
config_directory=/etc/tondik/configs
;if local=false, server is started on 0.0.0.0, if local=true then server is started on 127.0.0.1 (optional) - default value false
local=false
;custom response headers (optional) -  array of strings
headers[]=Server: SuperWebServer
headers[]=Header: CustomHeaderValue
;custom mime types (optional) - array of strings
;format: "extension,mime_type"
mime_types[]=php,text/php
mime_types[]=html,text/html
mime_types[]=htm,text/html
access_log=/var/log/webserver/access.log
error_log=/var/log/webserver/error.log
; default root folder if no domain is found
default_root=/var/www/default
; default index file if no domain is found (optional), because it will use index.html by default
index=index.html

Config for domain/subdomain/hostname

  • serving specific folder
    domain=example.com
    root=/var/www/example.com
    ; default index will be index.html, but can be changed by this option
    index=index.htm
    ; access_log and error_log is optional and will be inherited from main config
    ; but when specifying custom paths fro access and error log, both must be set
    ; otherwise single option will be ignored
    access_log=/var/log/webserver/example.com/access.log
    error_log=/var/log/webserver/example.com/error.log
  • proxy pass (reverse proxy)
    domain=something.example.com
    reverse_proxy=localhost:8080
    access_log=/var/log/webserver/example.com/access.log
    error_log=/var/log/webserver/example.com/error.log

Specification

  • support only static files (html,css,js,videos,images...)
  • support for HTTP 1.1
  • doesn't support keep-alive connection
  • support partial content:
    • when streaming video file, for example in vlc, you can skip through video file
    • supported only in VLC, because browsers are using same connection to do this and we don't support keep-alive connections

Testing

Dev mode

  • Logs are written in /tmp/log.txt
    ❯ wrk -t12 -c1000 -d30s http://localhost:8080
    Running 30s test @ http://localhost:8080
      12 threads and 1000 connections
      Thread Stats   Avg      Stdev     Max   +/- Stdev
        Latency    38.46ms    4.07ms 151.68ms   91.13%
        Req/Sec     2.15k   191.48     2.56k    82.77%
      773070 requests in 30.10s, 343.56MB read
      Socket errors: connect 0, read 773046, write 0, timeout 0
    Requests/sec:  25683.19
    Transfer/sec:     11.41MB
  • Logs are written to stdout
    ❯ wrk -t12 -c1000 -d30s http://localhost:8080
    Running 30s test @ http://localhost:8080
      12 threads and 1000 connections
      Thread Stats   Avg      Stdev     Max   +/- Stdev
        Latency    50.21ms    5.30ms 140.66ms   85.17%
        Req/Sec     1.65k   150.66     2.26k    79.20%
      592907 requests in 30.10s, 263.50MB read
      Socket errors: connect 0, read 592884, write 0, timeout 0
    Requests/sec:  19697.31
    Transfer/sec:      8.75MB

Server mode

  • Static files ❯ wrk -t12 -c1000 -d30s http://prvnistranka:8080 Running 30s test @ http://prvnistranka:8080 12 threads and 1000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 38.23ms 6.38ms 132.58ms 78.05% Req/Sec 2.16k 313.94 3.09k 68.12% 775178 requests in 30.10s, 1.00GB read Socket errors: connect 0, read 775161, write 0, timeout 0 Requests/sec: 25754.62 Transfer/sec: 33.92MB

  • Reverse proxy ❯ wrk -t12 -c1000 -d30s http://druhastranka:8080 Running 30s test @ http://druhastranka:8080 12 threads and 1000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 418.07ms 29.97ms 459.64ms 97.89% Req/Sec 210.67 109.07 595.00 65.80% 71001 requests in 30.05s, 604.70MB read Socket errors: connect 0, read 71001, write 0, timeout 0 Requests/sec: 2362.55 Transfer/sec: 20.12MB

tondikwebserver's People

Contributors

patrick11514 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.