Git Product home page Git Product logo

webserv's Introduction

Webserv

Webserv is a 42 project where you write your own HTTP server in C++. Find the subject here.

Our webserver uses the same non-blocking, event-driven architecture that nginx does. This allows the server to handle a high amount of requests with speed.
We use kqueue to handle the multiplexing, which means the server can only run on Mac machines.

Installation

Clone the repository:

git clone https://github.com/mariadaan/webserv.git

Compile the webserver through the makefile:

make

Run executable (optionally with a configuration file, which should be located in the root/conf folder. No need to specify the path.):

./webserver default_server.conf

Or run with default configuration through the makefile:

make run

Configuration

The server can be configured using a config file. The path-to-config file has to be added while running the server. Possible configurations:

  • Choose ports and servernames of virtual servers
  • Set up default error pages
  • Limit client body size
  • Set up routes with following possible configurations:
    • Define accepted HTTP methods
    • Set up HTTP redirections
    • Define root directory
    • Turn on/off directory listing
    • Setup index files
    • Execute CGI based on file extensions (currently only supports Python)

Specific config file rules:

  • All text that is not in a server block is not taken into account
  • All text gets truncated when a ';' or '#' is encounterd
  • Start of server block has to be written as "server {"
  • In the server body: only the following words are handled: 'listen', 'server_name', 'root', 'location', 'client_max_body_size', 'cgi', 'error_page'
  • In the location body: the following words are handled: 'index', 'request_method', 'upload', 'autoindex', 'redirect', 'client_max_body_size', 'root'
  • All other words are not taken into account
  • For the 'client_max_body_size' k/K are read as kilo (*1000) and m/M as mega (*1000000)

Resources

Visit this Notion page to read more about the components of a web server.

Our webserv team: Marius Pieter Maria

webserv's People

Contributors

mariadaan avatar mariusmivw avatar pderksen98 avatar

Stargazers

Omar Ibrahim avatar Jackson Uptain avatar  avatar

Watchers

 avatar  avatar

Forkers

42-mvan-wij

webserv's Issues

Error when doing request with unallowed method in CGI

curl -X DELETE localhost:8080/upload_file.py gives the following error:
webserv(19330,0x10c7dc5c0) malloc: *** error for object 0x7ff411c05ef0: pointer being freed was not allocated webserv(19330,0x10c7dc5c0) malloc: *** set a breakpoint in malloc_error_break to debug

change client functions

note to self: client functies die nu in de EventQueue.cpp eronder geplempt staan moeten even netjes een plekje krijgen, returns veranderen naar exceptions

Leaks

Ik krijg nog steeds een leak, deze was na siege runnen. Geen idee waar het zit

leaks Report Version: 4.0
Process 16170: 389 nodes malloced for 38 KB
Process 16170: 6 leaks for 864 total leaked bytes.

6 (864 bytes) ROOT CYCLE: 0x7f9df5402e50 [64]
   5 (800 bytes) ROOT CYCLE: 0x7f9df5405030 [64]
      CYCLE BACK TO 0x7f9df5402e50 [64]
      3 (672 bytes) ROOT CYCLE: 0x7f9df5404270 [64]
         1 (544 bytes) ROOT CYCLE: 0x7f9df5405880 [544]
         1 (64 bytes) ROOT CYCLE: 0x7f9df5405070 [64]
      1 (64 bytes) ROOT CYCLE: 0x7f9df5402e90 [64]

POST request without body

When a post request has no body and no content length, server should not crash

curl -X POST localhost:8080/posting

Infinite loop in CGI script

If there is an infinite loop in a cgi script, it just never finishes. Should we put a max runtime on a child process?

Check read/write requirements

  • There should be only one read or one write per client per select() (or equivalent). Ask the group to show you the code from the select() (or equivalent) to the read and write of a client.
  • Search for all read/recv/write/send and check if the returned value is correctly checked (checking only -1 or 0 values is not enough, both should be checked).
  • Search for all read/recv/write/send on a socket and check that, if an error is returned, the client is removed.
  • If errno is checked after read/recv/write/send, the grade is 0 and the evaluation process ends now.
  • Writing or reading ANY file descriptor without going through the select() (or equivalent) is strictly FORBIDDEN.

Make CGI non-blocking

We can maybe make the CGI non-blocking.
This would mean we have to add it to the EventQueue, and allows us to only call waitpid once we get EOF on a read. This could allow us to block our server shorter waiting for the CGI to finish.

Port issues

We need to make sure we pass the "Port issues" part of the eval sheet, so make sure we handle multiple ports with the same number and multiple ports with the same server_name well.

  • In the configuration file setup multiple ports and use different websites. Use the browser to ensure that the configuration works as expected and shows the right website.
  • In the configuration, try to setup the same port multiple times. It should not work.
  • Launch multiple servers at the same time with different configurations but with common ports. Does it work? If it does, ask why the server should work if one of the configurations isn't functional. Keep going.

Unknown request method

curl -X UNKNOWN localhost:8080 geeft segfault, die methods[UNKNOWN] = "??? UNKNOWN ???"; moet even weg

curl -X RANDOM localhost:8080 exit de server, of geeft pointer being freed was not allocated

CGI unsuccessful error message

If the script executed by the cgi has an error or can not be executed for another reason, we should send a response with the 500 Internal Server Error status code. I think we should do this by getting the exit code from the child process. If it's not equal to 0, we should respond with an error message. Now we just don't do anything. The server doesnt crash though.

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.