A HTTP server written in C++ from scratch
In construction (see the current plan)
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
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;
}
}
}
http
- The http block of the serverserver
- The server block of the serverevents
- The events block of the serverlocation
- The location block of the server
listen
- The port that the server will listen onserver_name
- The server name of the serverallow_methods
- Specify the allowed methods
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 typeserror_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 thecgi
directive.autoindex
- Specify whether to show directory listingscgi
- Specify a cgi script
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
Accepted git commit message tags:
- feat
- fix
- chore
- perf
- refactor
- doc
Code should follow the google cpp style