//
#include "plaqui/server/httpheaders.h"
+#include "plaqui/server/string.h"
//#include <cstdlib>
#ifdef DEBUG
# include <iostream>
#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) {
#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 string("Wrong header: ") + sbuf;
}
- (*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
+