Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Web Server

Description

This project is a HTTP server (Mini NGINX) that can handle multiple clients at the same time. It is able to serve static files and execute CGI scripts. It handles GET, POST and DELETE requests.

Installation

make

Usage

Run

./webserv [config_file]

Example:

./webserv config/basic.conf

Stop

Ctrl + C

Use

Web Browser

  • Open a web browser and go to http://localhost:1313/ to see the default page.
    • Config port is 1313 in the example config file. Modify the port number according to the config file.

curl

  • You can also use curl to send requests to the server.
    • -H flag is used to add headers to the request.
    • -X flag is used to specify the request method.
curl -X GET http://localhost:1313/

Documentation

Config file

Block server :

  • server_name [name of the server]
  • listen [port number]
  • client_max_body_size [size in Mb]
  • error_page [error code] [path to error file]

Inside a server block, we can have zero to many location blocks.

Location block [matching path] :

  • root [path] -> appends this path after the entry path
  • index [file name] -> default page if no file specified in the uri
  • autoindex [on|off] -> enables/disables the listing of directory
  • allowed_methods [GET|POST|DELETE] -> defines the allowed methods
  • cgi [.extension] [path to executable]
  • upload_file_path [directory path] -> location of the files to download

Demonstration with example config file

  1. Run the server with the example config file.
    make
    ./webserv config/basic.conf
  2. Open a web browser and go to http://localhost:1313/ to see the default page (with directory listing).
  3. Check cgi script by going to http://localhost:1313/ruby/
  4. Check the error page by going to http://localhost:1313/some_invalid_path
  5. Send a file using curl.
    touch test.txt
    curl -X POST -F "file=@./test.txt" http://localhost:1313/
  6. Check the uploaded file by going to http://localhost:1313/upload/
  7. Delete the uploaded file using curl.
    curl -X DELETE http://localhost:1313/upload/test.txt
  8. Check the deleted file by going to http://localhost:1313/upload/
  9. Check cookie by going to http://localhost:1313/python/

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages