Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zonyitoo/httpsrv
HTTP Server in C++ 11
https://github.com/zonyitoo/httpsrv
Last synced: 3 months ago
JSON representation
HTTP Server in C++ 11
- Host: GitHub
- URL: https://github.com/zonyitoo/httpsrv
- Owner: zonyitoo
- Created: 2013-11-09T05:12:09.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2013-11-11T07:33:46.000Z (about 11 years ago)
- Last Synced: 2023-04-09T22:19:21.384Z (over 1 year ago)
- Language: C++
- Size: 141 KB
- Stars: 3
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
HTTP Server
-----------A simple HTTP server in C++ 11.
Build
=====* Install ``SCons`` and ``clang``.
* Write a ``SConstruct`` file to build the library
.. code:: python
env = Environment()
env["CXX"] = "clang++"SConscript(['src/SConscript'])
env.Program('test', 'test.cpp',
LIBS=['srv', 'c++abi', 'c++'],
LIBPATH='src',
CPPFLAGS='-std=c++11 -stdlib=libc++ -g',
CPPPATH=['src'])* Run ``scons``.
Note: GCC currently doesn't support C++11's ``regex``. We have to use ``clang`` and ``libc++``.
Usage
=====.. code:: cpp
#include "server.h"
#include "ioloop.h"
#include "handler.h"using namespace httpserver;
class HelloWorldHandler : public HttpHandler {
public:
void get_handler(const HttpRequest& req, HttpResponse& resp,
const std::vector& args) {
resp.body = "Hello World!!";
resp.headers["Content-Type"] = "text/plain";}
};int main(int argc, char **argv) {
EPollIOLoop ioloop(argc, argv);HttpServer server(800, 5, ioloop);
server.register_handler("/", new HelloWorldHandler());
server.register_handler("/([^/]*)/", new HelloWorldHandler());return ioloop.start();
}