Coder Social home page Coder Social logo

web-server's Introduction

Web-Server

Introduction

An implementation of HTTP server based on c++11, which is easily to add a Cgi instance. It can handle static resources, support HTTP long connections, and so on. We also implement the Asynchronous Log to record the status of the server.

Test page ๏ผšExampleCgi, LoginCgi and UploadCgi

Build

a) To Compile source files into binary executables (in the root folder)

bash install.sh

b) Run the program (in the build folder)

cd build
./httpcgiservermain

Steps of adding a Cgi instance

a) Write a Cgi instance class, which inherits the BaseCgi class, like ExampleCgi.

b) Add the Cgi instance into the CgiInstanceFactory.

c) Add the header file into the CgiHeader.

d) Modify the CMakeLists.txt.

e) Then build and run.

Pressure measurement

Test result by webBench is shown in Here.

Repository contents

See implDoc.md for a brief overview of the implementation. Guide to header files:

  • base/log.h Interface for log system, which is from Asynchronous Log.

  • epoller.h Encapsulate related functions of epoll.

  • netutil.h Encapsulate related functions of socket fd.

  • simplebuffer.h Application layer buffer(we only implement the LT model now).

  • channel.h Encapsulate channel(event) related callback functions (read/write/error functions).

  • minheap.h Use min heap to manage the expired time of connection.

  • eventloop.h It manages the channel(event), which is registed to the epoller, and process the active channels(events).

  • eventloopthread.h It manage a connect queue, and the main accept thread push connection socket fd into the queue, then this thread add the socket fds to its eventLoop.

  • eventloopthreadpool.h It manage several threads, the main accept thread push connection socket fd into the threadpool, it dispatches the socket to its threads.

  • tcpserver.h Accept connection socket fd, and when a read event happends on the connection socket, it automatically read the byte stream into the application buffer of the channel, and execute the read callback function. The same as write and error events happend.

  • httpmessage.h Parse the HTTP request, build HTTP respond message. Here, we use a state machine to process HTTP requests.

  • basecgi.h The abstract class of Cgi instance class. It provides a Process interface, we use it to process the cgi request.

  • includecgiheader.h Include the Cgi instance class, which is used for cgidispatch.

  • cgidispatch.h The Cgi dispatcher, which use the url to find the Cgi instance, to execute the cgi program.

  • httpcgiserver.h When read event happend, it firstly parses the http request in the application buffer of the channel, then finds the cgi instance and process the request.

  • httpcgiservermain.cpp HTTP server main.

  • exampleCgi/examplecgi.h and loginCgi/logincgi.h Example of how to write a Cgi instance class. webFile/login includes the .html, .js, .css files needed by the LoginCgi class.

web-server's People

Contributors

stepbysteptosky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.