Clone wiki

libhttpd / Home


libhttpd project is still in under development.
So I can't prepare documentation now.

See also sample project using libhttpd:


#include "stdafx.h"

#include <libhttpd.h>
#include <boost/bind.hpp>
#include <boost/date_time.hpp>
#include <boost/regex.hpp>
#include <boost/filesystem.hpp>

#include <iostream>
#include <fstream>

using namespace std;
using namespace boost;

namespace bfs = boost::filesystem;

void root_handler(const request& req, response& res)
  gregorian::date d(gregorian::day_clock::universal_day());
  res <<
        "<p>" << d << "</p>"

void regex_handler(const request& req, response& res)
  res <<
      "<head><title>regex handler</title></head>"
        "<h1>handle all .html or .htm requests</h1>"
        "<p>" << req.m_path << "</p>"

int _tmain(int argc, _TCHAR* argv[])
  http_server server;

  // maps constant URI to handler function
  server.set_handler("/", root_handler);

  // maps regex URI to handler function
  server.set_handler(regex("/.+\\.html?$"), regex_handler);

  // maps constant URI to file
  server.set_handler("/ja", "ja.html");
  server.set_handler("/img/hoge.png", "hoge.png");

  // maps constant URI to directory
  server.set_handler("/help", "help/");

  cout << "listening started" << endl;

  // start listening

  return 0;