summaryrefslogtreecommitdiff
path: root/http_static.cpp
blob: a0856f49421595aa69b3cf4db42999b36e94e4c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "http_static.h"

#include <boost/filesystem/fstream.hpp>
#include <boost/format.hpp>

HTTP::Static::Static(fs::path directory, std::string index) : directory_(directory), index_(index) {
	
}

void HTTP::Static::operator()(Connection::p connection) {
	fs::path path = directory_;
	
	if(connection->path.size()) {
		for(Connection::PathList::iterator it = connection->path.begin(); it != connection->path.end(); it++) {
			path /= *it;
		}
	} else {
		path /= index_;
	}
	
	if(fs::is_regular_file(path)) {
		connection->send_file(path);
	
	} else if(fs::exists(path)) {
		connection->send_error(403);
	} else {
		connection->send_error(404);
	}
}