X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/1b53a979e1de9034a9755955ea22cd40ed138f23..0d72fb12dc9a570be45e2f25320ac49f604c3ed2:/Server/src/httpheaders.cpp diff --git a/Server/src/httpheaders.cpp b/Server/src/httpheaders.cpp index 67ec270..04bd6c8 100644 --- a/Server/src/httpheaders.cpp +++ b/Server/src/httpheaders.cpp @@ -26,40 +26,57 @@ // #include "plaqui/server/httpheaders.h" +#include "plaqui/server/httperror.h" +#include "plaqui/server/string.h" //#include #ifdef DEBUG # include #endif // DEBUG -PlaQui::Server::HTTPHeaders::~HTTPHeaders(void) { +using namespace std; + +namespace PlaQui { + +namespace Server { + +HTTPHeaders::~HTTPHeaders(void) { #ifdef DEBUG - std::cerr << __FILE__ << ": destructor." << std::endl; + cerr << __FILE__ << ": destructor." << endl; #endif // DEBUG } -istream& operator>>(std::istream& is, PlaQui::Server::httpheaders& h) { +istream& operator>>(istream& is, HTTPHeaders& h) throw(HTTPError) { #ifdef DEBUG - std::cerr << __FILE__ << ": operator>>()" << std::endl; + cerr << __FILE__ << ": operator>>()" << endl; #endif // DEBUG char buf[BUFSIZ]; is.getline(buf, BUFSIZ); - std::string sbuf = buf; - std::string::size_type pos = sbuf.find(":"); - if (pos == std::string::npos) { + string sbuf = buf; + string::size_type pos = sbuf.find(":"); + if (pos == string::npos) { // FIXME poner mejores excepciones. - throw "Wrong header"; + throw HTTPError(400, sbuf + ": No es una cabecera vĂ¡lida."); } - (*this)[sbuf.substr(0, pos)] = sbuf.substr(pos + 1); + h[sbuf.substr(0, pos)] = String(sbuf.substr(pos + 1)).trim(); +#ifdef DEBUG + cerr << __FILE__ << " " << sbuf.substr(0, pos) << " = " + << h[sbuf.substr(0, pos)] << endl; +#endif // DEBUG return is; } -ostream& operator<<(std::ostream& os, PlaQui::Server::HTTPMessage) { +ostream& operator<<(ostream& os, const HTTPHeaders& h) { #ifdef DEBUG - std::cerr << __FILE__ << ": operator<<()" << std::endl; + cerr << __FILE__ << ": operator<<()" << endl; #endif // DEBUG - for (HTTPMessage::const_iterator i = begin(); i != end(); ++i) { - os << i->first << ": " << i->second << "\r\l"; + for (HTTPHeaders::const_iterator i = h.begin(); + i != h.end(); ++i) { + os << i->first << ": " << i->second << "\r\n"; } return os; } +} // namespace Server + +} // namespace PlaQui +