X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/f27c218d18ebf7198e07249aca1eed625da914fd..dea314b92324ad67455bb039e2078652ab0e5824:/Server/src/httpheaders.cpp?ds=inline diff --git a/Server/src/httpheaders.cpp b/Server/src/httpheaders.cpp index 0ec62e1..b54201e 100644 --- a/Server/src/httpheaders.cpp +++ b/Server/src/httpheaders.cpp @@ -25,8 +25,9 @@ // $Id$ // -#include "plaqui/server/httpheaders.h" #include "plaqui/server/httperror.h" +#include "plaqui/server/httpmessage.h" +#include "plaqui/server/httpheaders.h" #include "plaqui/server/string.h" //#include #ifdef DEBUG @@ -41,37 +42,45 @@ namespace Server { HTTPHeaders::~HTTPHeaders(void) { #ifdef DEBUG - cerr << __FILE__ << ": destructor." << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": destructor." << endl; #endif // DEBUG } -istream& operator>>(istream& is, HTTPHeaders& h) throw(HTTPError) { +istream& operator>>(istream& is, HTTPHeaders& h) + throw(HTTPError, sockerr, ios::failure) { #ifdef DEBUG - cerr << __FILE__ << ": operator>>()" << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": operator>>()" << endl; #endif // DEBUG char buf[BUFSIZ]; - is.getline(buf, BUFSIZ); + // Fin del stream, no había cabeceras. + if (!is.getline(buf, BUFSIZ)) { + throw ios::failure("eof"); + } string sbuf = buf; string::size_type pos = sbuf.find(":"); if (pos == string::npos) { // FIXME poner mejores excepciones. - throw HTTPError(400, sbuf + ": No es una cabecera válida."); + throw HTTPError(HTTPMessage::BAD_REQUEST, sbuf + ": No es una cabecera válida."); } h[sbuf.substr(0, pos)] = String(sbuf.substr(pos + 1)).trim(); #ifdef DEBUG - cerr << __FILE__ << " " << sbuf.substr(0, pos) << " = " + cerr << __FILE__ << "(" << __LINE__ << ")" + << " " << sbuf.substr(0, pos) << " = " << h[sbuf.substr(0, pos)] << endl; #endif // DEBUG return is; } -ostream& operator<<(ostream& os, const HTTPHeaders& h) { +ostream& operator<<(ostream& os, const HTTPHeaders& h) throw(sockerr) { #ifdef DEBUG - cerr << __FILE__ << ": operator<<()" << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": operator<<()" << endl; #endif // DEBUG for (HTTPHeaders::const_iterator i = h.begin(); i != h.end(); ++i) { - os << i->first << ": " << i->second << "\n\r"; + os << i->first << ": " << i->second << "\r\n"; } return os; }