nullswan / webserv Goto Github PK
View Code? Open in Web Editor NEWHTTP/1.1 compliant and resilient server. Nginx based. Supporting CGI and session/cookies.
HTTP/1.1 compliant and resilient server. Nginx based. Supporting CGI and session/cookies.
Handle Location blocks and their attributes.
Restrict support to HTTP/1.1 or HTTP/1.0 ONLY.
In any other cases, we must return a 505 error.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/505
/!\ In HTTP 1.0, the connection is closed by default.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection
Enhance Client timeout checker.
In case our server is under high load, we must still trigger garbage collection.
This will be also used to clear any CGI process that are running for too long.
View: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
check for cgi,
check for upload,
otherwise, send a 403 (Forbidden) https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403
View: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE
resolve_uri => using location
if ( stat(file) )
if (delete())
return 204
if (not allowed())
return 403
if (error())
return 500
if (not found)
return 404
Depend of #7
Setup default settings when no argument (ie. no config file) is passed.
Default config eventually expose a /ping GET endpoint, otherwise anything will be 404.
(Default autoindex off)
Handle chuncked_request using special body reader.
Send a 408 error page to timed out clients.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408
Handle timed out client by destroying their Webserv::Http::Client
object.
Process GET CGI
Setup following rules:
server {
server_name (IServer._name<std::string>)
listen (IServer._host<std::string>):(IServer._port<int>);
// or
listen :(IServer._port<int>);
// or
listen (IServer._port<int>);
// or
listen (IServer._host<std::string>); // port 80 is used
/*
If listen is not defined, *:80 is used
if webserv runs with the superuser privileges,
or *:8000 otherwise.
*/
}
Handle CGI system.
This must be asynchronous.
In case a CGI is too long, it must be killed by our garbage collector, triggered when epoll_wait contain no events, view #14 .
Define how we await CGI.
Return error if file is empty
Make logger uri placeholder longer to prevent overlap.
[WEBSERV] 2021/12/01 - 13:54:49 | GET / | 404 | 63 μs | 127.0.0.1 -> 0.0.0.0
[WEBSERV] 2021/12/01 - 13:54:49 | GET /favicon.ico | 404 | 34 μs | 127.0.0.1 -> 0.0.0.0
It should be aligned, ie:
[WEBSERV] 2021/12/01 - 13:54:49 | GET / | 404 | 63 μs | 127.0.0.1 -> 0.0.0.0
[WEBSERV] 2021/12/01 - 13:54:49 | GET /favicon.ico | 404 | 34 μs | 127.0.0.1 -> 0.0.0.0
View: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host
The host header is not optional and must appear in any HTTP/1.1 request. If it is missing or contains multiple Header fields, we should return 400 (Bad Request).
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET
resolve_uri => use locations
( is_cgi() )
handle_cgi()
// direct file serv
( stat() == -1 )
404 not found, 500 server error
if (path_is_directory)
try config.index resolve, catch 500 (Server Error)
try autoindex, catch 500 (Server Error)
=> 404
Handle server block with their attributes.
In case we have a duplicate host:port, only the first one will be used.
Raise error when attempting to configure a nested location.
Call a specific method invoker depending on the HTTP method provided within the request.
Otherwise, return a 501 error if none match.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/501
if (GET)
=> GET()
if (POST)
=> POST()
if (DELETE)
=> DELETE()
return (501, NOT IMPLEMENTED)
Resolve $query, replacing them with real value and calling the correct server by returning 301 (Moved Permanently: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/301)
Pre-generate any error pages, load from file if supplied in configuration file.
Solver must split at ':' if any, meaning there is a port and attempt to match the extract port with a matching vhost if any has been found.
Response must be sent with some header any time:
Setup a upload pass member that allowed file upload and root them to this specific directory.
Handle virtuel hosts when merging servers.
If one vHost exist, we must try to match before using default server host configuration.
Setup Webserv::Http::Request
object lifetime.
This object should be instanced while reading request in Webserv::Http::Client
.
He must contains several members referring to her buffer parsing result.
Along with several methods, is this a closed, chuncked request ?
Handle IBLock and their attributes.
Build an autoindex generator.
Used by: #13
Handle body size being too large.
Client usually send Content-Length header withing their payload. (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Length)
We can use this header to prevent full reading of a payload.
In case the payload size is too large, we can return a 413 error. https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/413
Define and handle behavior when there is a duplication for a specific host:port key.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.