X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/f27c218d18ebf7198e07249aca1eed625da914fd..c90e905d76aed75379d220478e97fda0d34ec59b:/Server/src/httprequest.cpp?ds=inline diff --git a/Server/src/httprequest.cpp b/Server/src/httprequest.cpp index f1119fd..1da38a7 100644 --- a/Server/src/httprequest.cpp +++ b/Server/src/httprequest.cpp @@ -39,55 +39,49 @@ namespace Server { HTTPRequest::~HTTPRequest(void) { #ifdef DEBUG - cerr << __FILE__ << ": destructor." << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": destructor." << endl; #endif // DEBUG } HTTPRequest::HTTPRequest(const string& uri, const HTTPMethod& method, - const string& query, const string& version): - HTTPMessage(version), method(method), uri(uri), query(query) { + const string& query, const string& body, const string& version): + HTTPMessage(body, version), method(method), uri(uri), query(query) { #ifdef DEBUG - cerr << __FILE__ << ": uri = " << uri << " | " - << "method = " << ((method == GET) ? "GET" : "POST") << " | " + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": uri = " << uri << " | " + << "method = " << method_str() << " | " << "query = " << query << " | " + << "body.length = " << body.length() << " | " << "version = " << version << endl; #endif // DEBUG } -/* -HTTPRequest::HTTPRequest(const Serializable& body, - const string& version): - HTTPMessage(body, version) { -#ifdef DEBUG - cerr << __FILE__ << ": http_version = " << http_version - << " | body = " << body.serialize() << endl; -#endif // DEBUG -} - -HTTPRequest::HTTPRequest(const string& uri, - const HTTPRequest::HTTPMethod& method, - string& query, string& version): - HTTPMessage(body, version) { -#ifdef DEBUG - cerr << __FILE__ << ": http_version = " << http_version - << " | body = " << body.serialize() << endl; -#endif // DEBUG +string HTTPRequest::method_str(void) const { + switch (method) { + case POST: + return "POST"; + case GET: + default: + return "GET"; + } } -*/ istream& operator>>(istream& is, HTTPRequest& req) - throw(HTTPError, ios::failure) { + throw(HTTPError, 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 más 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. @@ -154,16 +148,17 @@ istream& operator>>(istream& is, HTTPRequest& req) return is; } -ostream& operator<<(ostream& os, const HTTPRequest& req) { +ostream& operator<<(ostream& os, const HTTPRequest& req) throw(sockerr) { #ifdef DEBUG - cerr << __FILE__ << ": operator<<()" << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": operator<<()" << endl; #endif // DEBUG - os << req.method << " " << req.uri; + os << req.method_str() << " " << req.uri; if (req.query.length()) { os << "?" << req.query; } - // TODO ver que este bien el \n/r - os << " HTTP/" << req.version << "\n\r" << static_cast(req); + os << " HTTP/" << req.version << "\r\n" + << static_cast(req); return os; }