GithubHelp home page GithubHelp logo

scarletsang / web_serv Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sangyao42/web_serv

0.0 0.0 0.0 595 KB

Shell 1.03% C++ 92.73% Makefile 2.16% Dockerfile 0.10% HTML 2.61% JavaScript 0.05% Python 1.31%

web_serv's Introduction

Web Server

A HTTP server written in C++ from scratch

Design

In construction (see the current plan)

Specification

Supported HTTP Fields

The syntax for each fields are specified in necessary_fields.abnf

Fields when the HTTP message has a body:

  • Content-Type
  • Content-Length
  • Content-Location

Fields in both HTTP request and response:

  • Connection

Fields only in HTTP request:

  • Host
  • Referer

Fields only in HTTP response:

  • Last-Modified
  • Allow
  • Location
  • Server
  • User-Agent

Grammer for the HTTP parser can be read here

Supported server configuration directives

http {
     types {
        text/html html;
        text/css css;
        text/javascript js;
        image/png png;
        image/jpeg jpeg;
        image/gif gif;
        application/json json;
    }

    server {
        listen 8080;
        server_name my.com;
        root /var/www/html;
        index index.html;
        autoindex on;
        error_pages 404 /404.html;
        access_log /var/log/access.log;
        error_log /var/log/error.log;
        location / {
            cgi py /cgi-bin;
        }
        location /images {
            allow_methods POST DELETE;
            return 301 /new;
        }
        location /images2 {
            return 307 https://www.google.com;
        }
        location /cgi-bin {
            allow_methods DELETE;
            return 200 "you are welcome";
        }
		location /hello {
			return 404;
		}
    }
}

Block directives

  • http - The http block of the server
  • server - The server block of the server
  • events - The events block of the server
  • location - The location block of the server

Directives related to HTTP requests

  • listen - The port that the server will listen on
  • server_name - The server name of the server
  • allow_methods - Specify the allowed methods

Directives for HTTP response generation

Generating a response from a requested file:

  • root - The root directory of the server.
  • index - The index files of the server. If autonindex is off, a HTTP request that ends with a '/' will try to return the first found index file instead.
  • types - Map response file name extensions to MIME types
  • error_pages - The error page of the server

Generating a response by other means:

  • client_max_body_size - The maximum body size of the client. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client.
  • return - returns a response with the specified status code. Redirections are handled by this directive: temporily (307) or permanantly (301) redirection. If the status code is not a redirection, it can also return a string that will be sent in the HTTP response body. Return has the highest priority than the cgi directive.
  • autoindex - Specify whether to show directory listings
  • cgi - Specify a cgi script

Misc directives

For logging information:

  • access_log - The access log file of the server

  • error_log - The error log file of the server

  • worker_connections - Maximum amount of connections that the server will handle at any given point of time

See the properties of all supported directives here Grammer for the configuration parser can be read here

External materials

Collaboration notes

Accepted git commit message tags:

  • feat
  • fix
  • chore
  • perf
  • refactor
  • doc

Code should follow the google cpp style

web_serv's People

Contributors

sangyao42 avatar scarletsang avatar scaletsang avatar euns-kim 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.