Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
42 lines (33 sloc) 1.07 KB
// Copyright 2012, Evan Klitzke <>
#include <iostream>
#include <boost/asio.hpp>
#include <boost/program_options.hpp>
#include "./src/garfield.h"
namespace po = boost::program_options;
void HelloWorldHandler(garfield::Request *req, garfield::Response *resp) {
resp->headers()->SetHeader("Content-Type", "text/plain");
resp->Write("Hello, world!\n");
int main(int argc, char **argv) {
po::options_description desc("Allowed options");
("help", "produce help message")
("port,p", po::value<int>()->default_value(8000),
"the port to bind on")
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
if (vm.count("help")) {
std::cout << desc;
return 1;
boost::asio::io_service io;
garfield::HTTPServer server(&io);
server.AddRoute("GET", "/", HelloWorldHandler);
server.AddRoute("GET", ".*", garfield::StaticFileHandler);; // start the main loop
return 0;
Something went wrong with that request. Please try again.