1. Yuki Kodama
  2. libhttpd

Wiki

Clone wiki

libhttpd / Home

Welcome

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

See also sample project using libhttpd:
http:bitbucket.org/kuy/libhttpd_sample/

Example

#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 <<
    "<html>"
      "<head><title>hw!</title></head>"
      "<body>"
        "<h1>hw!</h1>"
        "<p>" << d << "</p>"
      "</body>"
    "</html>";
}

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

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
  server.start();

  return 0;
}

Updated