X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/1b53a979e1de9034a9755955ea22cd40ed138f23..ad06ae2e40db5ce588092d90e1e089f527c27f84:/Server/src/httpheaders.cpp diff --git a/Server/src/httpheaders.cpp b/Server/src/httpheaders.cpp index 67ec270..0ec62e1 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 << "\n\r"; } return os; } +} // namespace Server + +} // namespace PlaQui +