X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/bcbe297964b0ad7393385f1dd240448c340ed5ed..HEAD:/Server/src/httpresponse.cpp?ds=sidebyside diff --git a/Server/src/httpresponse.cpp b/Server/src/httpresponse.cpp index 46cc55e..2ae86a9 100644 --- a/Server/src/httpresponse.cpp +++ b/Server/src/httpresponse.cpp @@ -40,14 +40,16 @@ namespace Server { HTTPResponse::~HTTPResponse(void) { #ifdef DEBUG - cerr << __FILE__ << ": destructor." << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": destructor." << endl; #endif // DEBUG } HTTPResponse::HTTPResponse(const string& body, const string& version): HTTPMessage(body, version) { #ifdef DEBUG - cerr << __FILE__ << ": body.length = " << body.length() + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": body.length = " << body.length() << " | version = " << version << endl; #endif // DEBUG } @@ -55,34 +57,38 @@ HTTPResponse::HTTPResponse(const string& body, const string& version): HTTPResponse::HTTPResponse(const HTTPError& error): status_code(error.code) { #ifdef DEBUG - cerr << __FILE__ << ": HTTPError(status_code = " << error.code + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": HTTPError(status_code = " << error.code << ", reason = " << HTTPMessage::reason(error.code) << ", desc = " << error.what() << ")" << endl; #endif // DEBUG - set_body(string(""); + set_body(string(""); } HTTPResponse::HTTPResponse(unsigned status_code, const string& body): HTTPMessage(body), status_code(status_code) { #ifdef DEBUG - cerr << __FILE__ << ": status_code = " << status_code + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": status_code = " << status_code << " | body.length = " << body.length() << endl; #endif // DEBUG } istream& operator>>(istream& is, HTTPResponse& resp) - throw (HTTPResponse::Error, ios::failure) { + throw (HTTPResponse::Error, sockerr, ios::failure) { #ifdef DEBUG - cerr << __FILE__ << ": operator>>()" << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": operator>>()" << endl; #endif // DEBUG char buf[BUFSIZ]; // Obtengo primera línea (request) if (!is.getline(buf, BUFSIZ)) { - // No hay mas líneas. - throw ios::failure("socket closed"); + // Fin de archivo. + throw ios::failure("eof"); } #ifdef DEBUG - cerr << __FILE__ << ":\tRecibiendo linea: " << buf << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ":\tRecibiendo linea: " << buf << endl; #endif // DEBUG String line(buf); // Si es la primera línea, es el request. @@ -116,16 +122,15 @@ istream& operator>>(istream& is, HTTPResponse& resp) if (line.length() != 3) { throw HTTPResponse::INVALID_HTTP_RESPONSE_CODE; } - stringstream ss; - ss << line; // TODO ver forma mas linda de convertir - ss >> resp.status_code; + to(line, resp.status_code); is >> static_cast(resp); return is; } -ostream& operator<<(ostream& os, const HTTPResponse& resp) { +ostream& operator<<(ostream& os, const HTTPResponse& resp) throw(sockerr) { #ifdef DEBUG - cerr << __FILE__ << ": operator<<()" << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": operator<<()" << endl; #endif // DEBUG os << "HTTP/" << resp.version << " " << resp.status_code << " " << HTTPMessage::reason(resp.status_code) << "\r\n";