X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/a143e957a68145eece4b5b60e0bf8bee0d0693cd..6bffb655ac989fe4f115763270f84175bf24e4bb:/Server/src/httpheaders.cpp?ds=sidebyside diff --git a/Server/src/httpheaders.cpp b/Server/src/httpheaders.cpp index cef6d05..0ec62e1 100644 --- a/Server/src/httpheaders.cpp +++ b/Server/src/httpheaders.cpp @@ -26,13 +26,18 @@ // #include "plaqui/server/httpheaders.h" +#include "plaqui/server/httperror.h" +#include "plaqui/server/string.h" //#include #ifdef DEBUG # include #endif // DEBUG using namespace std; -using namespace PlaQui::Server; + +namespace PlaQui { + +namespace Server { HTTPHeaders::~HTTPHeaders(void) { #ifdef DEBUG @@ -40,7 +45,7 @@ HTTPHeaders::~HTTPHeaders(void) { #endif // DEBUG } -istream& operator>>(istream& is, HTTPHeaders& h) { +istream& operator>>(istream& is, HTTPHeaders& h) throw(HTTPError) { #ifdef DEBUG cerr << __FILE__ << ": operator>>()" << endl; #endif // DEBUG @@ -50,9 +55,13 @@ istream& operator>>(istream& is, HTTPHeaders& h) { 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."); } - h[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; } @@ -62,8 +71,12 @@ ostream& operator<<(ostream& os, const HTTPHeaders& h) { #endif // DEBUG for (HTTPHeaders::const_iterator i = h.begin(); i != h.end(); ++i) { - os << i->first << ": " << i->second << "\r\n"; + os << i->first << ": " << i->second << "\n\r"; } return os; } +} // namespace Server + +} // namespace PlaQui +