Skip to content

BPhilagor/WebServ

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebServ

An https server written in c++98 capable of hadeling POST, GET and DELETE. Developed as pert of the ecole 42 cursus.

Config file

To configure the server we need to abhear to the rules outline in the doc.

The config file is strucrued like so:

server billy {
	listen = 8080
	server_name = something www.something.com
	location / {
		alias = html
	}
}

Redirections

It is possible to configure client HTTP redirects using the redir directive. Example:

server test-server {
	listen = 8080
	server_name = test
	location /redirected {
		redir = https://www.google.com temporary
	}
}

It is possible to configure a permanent redirect using redir = https://www.google.com permanent. The difference between temporary and permanent is the HTTP status code that is returned to the client.

Static file uploads using POST methods

It is possible to accept uploaded files without a CGI. For this to work, the upload_dir directive must be set. Else, a "405 Method not allowed" error will be returned. Files uploaded using the POST method with a content-type of multipart/form-data will be saved in a random folder inside the upload_dir in order to prevent conflicts. If content-type is not multipart/form-data, a "400 Bad request" error will be returned. (That means that in an html form, the enctype attribute must be set to multipart/form-data.)

config file parsing

The config file is parsed using recursion and the Data class as the singular node that holds data. The hierarchy produced from parsing is what later needs to be interogated to configure the server.

typedef std::pair<std::string, Data> dataObj;  //pairs of object name and the object
class Data
{
    [...]
    std::string _content;                      // the contents of the node as string
    std::vector<dataObj> _vecObjs;             // a vector of pairs
    [...]
}

After parsing internal structure is aproximated to this ...

Argh this is getting to a a mess to try show, grossomodo there are two types of data bits.

A straight forward property ip = 192.168.1.1 A container of more properties ports {

If it's a straignt forward property look at the content to get the 192.168.1.1 and the parent nodes string pair for the property name ip. Same goes for the container.

In this way property names are always in the pair string and the content/value is in the _content.

Data node;
Data::readFile(node, path);

std::cout << node.getObj(0).first << "\n";
std::cout << node.getObj(0).second.getObj(0).first << "\n";
std::cout << node.getObj(0).second.getObj(0).second.getContent() << "\n";

// but now we have a new way of doing things but it's not detailed here.
...

server
url
https://example.com/

Maybe an idea might be to overload the [] for data, so it's shorthand for the .getObj(n). Acess could look like this node[0].second[0].first;

Pour curl test :

curl --resolve "helloworld:8080:127.0.0.1" "helloworld:8080"
curl -X POST -H "Content-Type:plain/text" --data "BODY goes here" --resolve test:8080:127.0.0.1 test:8080

About

Notre projet web server pour 42 Lausanne

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages