30 #include <boost/lexical_cast.hpp>
31 #include <boost/regex.hpp>
35 using boost::lexical_cast;
39 size_t CosResposta::envia(
socket_tcp & socket,
const string & buffer)
const
44 if (0 == pTrans.get()) {
49 dades = pTrans->transforma( buffer );
51 return envia_literal(socket, dades);
54 size_t CosResposta::envia_literal(
socket_tcp & socket,
const string & buffer)
const
62 return boost::asio::write(socket, boost::asio::buffer(buffer));
64 catch (
const boost::system::system_error &) {
72 if (0 != trans_.get()) {
73 envia_literal(socket, trans_->finalitza());
81 tc.push_back( make_pair(
"Content-Encoding", ce_) );
84 tc.push_back( make_pair(
"Transfer-Encoding", te_) );
89 void CosResposta::determina_codificacions() {
90 using namespace boost;
93 chunked_ok_ = peticio().versio() >=
HTTP_1_1;
106 assert( peticio().versio() >=
HTTP_1_1 );
109 const string tr = peticio().capsalera(
"Accept-Encoding");
110 if (tr.empty() ||
"identity" == to_lower_copy(tr)) {
117 char_separator<char> separador(
",");
118 tokenizer< char_separator<char> > tokens(tr, separador);
123 const boost::regex re_espais(
"\\s*");
124 for (
auto it=tokens.begin(); it != tokens.end(); ++it) {
126 const string enc = boost::regex_replace(*it, re_espais,
"");
128 if (
"deflate" == to_lower_copy(enc)) {
134 assert( chunked_ok_ );
149 trans_.reset( pTrans );
155 string CosPaginaError::html()
const {
156 if (!cache_.empty()) {
162 const string titol = lexical_cast<
string>(
static_cast<int>(error_)) +
": " +
165 ss <<
"<!DOCTYPE html>\n"
168 "\t<title>" << titol <<
"</title>\n"
171 "\t<h1>Error " << titol <<
"</h1>\n"
172 "\t<p>" << missatge_ <<
"</p>\n"
174 "\t<address>" << Servidor::signatura() <<
"</address>\n"
184 c.push_back( make_pair(
"Content-Type",
"text/html; charset=utf-8") );
185 c.push_back( make_pair(
"Content-Length", lexical_cast<string>(html().length())) );