Skip to content

A tiny, fast and powerful webserver (http and https) for linux

Notifications You must be signed in to change notification settings

titicplusplus/WebServer

Repository files navigation

WebServer

A web server for http and https requests

Installation

cmake .
make
sudo make install

How to use ?

To use, you need to inherit the following classes.

For a http web server;

// webserver.hpp
#pragma once

#include <WebServerHttp.hpp>

class WebServer : public WebServerHttp {
	public:
		virtual std::string getContent(std::string &url, std::string &type, char *buffer, int bufferSize,
				const Paramters &params);
};

For a https web server;

// webserver.hpp
#pragma once

#include <WebServerHttps.hpp>

class WebServer : public WebServerHttps {
	public:
		virtual std::string getContent(std::string &url, std::string &type, char *buffer, int bufferSize,
				const Paramters &params);
};

And cpp files

#include "webserver.hpp"
#include <fstream>
#include <curl/curl.h>

std::string WebServer::getContent(std::string &url, std::string &type, char *buffer, int bufferSize) {
	std::string content;

	if (url == "/") {
		content = open_file("index.html");
	} else {
		content = open_file(url.substr(1));
	}

	return content;
}

And the main.cpp to launch the web server:

#include "webserver.hpp"
#include <csignal>
#include <fstream>

WebServer server;

void end_signal(int signal) {
	std::cout << "signal: " << signal << std::endl;
	server.stop(signal);
}


int main() {
	std::signal(SIGINT, end_signal);
	std::signal(SIGTERM, end_signal);


	// For an http web server
	server.config_server(8080);
	// For an https web server
	server.config_server(8080, "certs/testCA.crt", "certs/testCA.key");
		
	server.start(true);

	return 0;
}

About

A tiny, fast and powerful webserver (http and https) for linux

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published