36 #include <boost/asio.hpp>
37 #include <boost/tokenizer.hpp>
38 #include <boost/lexical_cast.hpp>
39 #include <boost/regex.hpp>
41 using namespace boost::asio::ip;
42 using namespace boost::filesystem;
66 :
CosResposta(peticio), arrel_servidor_(arrel_servidor)
69 assert( exists(arrel_servidor) && is_directory(arrel_servidor) );
70 assert( arrel_servidor.is_absolute() );
71 assert( canonical(arrel_servidor) == arrel_servidor );
73 const string ruta_peticio = peticio.ruta().ruta();
74 const path arrel_i_peticio(arrel_servidor_ /
path(ruta_peticio));
75 if (!exists(arrel_i_peticio)) {;
78 assert( exists(arrel_i_peticio) );
79 const path ruta_en_disc(canonical(arrel_i_peticio));
86 fisica_ = ruta_en_disc;
88 assert( fisica_.is_absolute() );
89 assert( canonical(fisica_) == fisica_ );
92 void Recurs::envia(tcp::socket & socket)
const throw (runtime_error)
95 istream_iterator<char[MIDA_BUFFER]> begin(ifs), end();
96 ostream_iterator<char[MIDA_BUFFER]> osi(gc.osi());
99 ifstream ifs(fisica_.string().c_str(), ifstream::in | ifstream::binary);
101 std::array<char, MIDA_BUFFER> buffer;
105 assert( canonical(fisica_) == fisica_ );
107 assert( is_regular_file(fisica_) );
109 while (ifs.good() && socket.is_open()) {
110 ifs.read(buffer.data(), buffer.size());
111 const streamsize bytes = ifs.gcount();
112 const string bloc(buffer.data(), bytes);
113 this->envia(socket, bloc);
122 using namespace boost;
124 assert( is_regular_file(fisica()) );
127 const string mida = lexical_cast<
string>(file_size(fisica()));
128 const time_t
mtime = filesystem::last_write_time(fisica());
129 capsaleres.push_back( make_pair(
"Last-Modified",
data_http(
mtime)) );
130 capsaleres.push_back( make_pair(
"ETag", this->entity_tag()) );
132 capsaleres.push_back( make_pair(
"Content-Type", mime) );
140 if (0 == transformacio().
get()) {
142 capsaleres.push_back( make_pair(
"Content-Length",
mida) );
148 string Recurs::entity_tag()
const {
154 const time_t
mtime = last_write_time(fisica_);
155 const size_t mida = file_size(fisica_);
157 const size_t hsh = hash<string>()(fisica_.string());