#include "HTTPPUTHandler.h"
#include "HTTPSession.h"
#include "HTTPServer.h"
#include "HTTPRequest.h"
#include "ZString.h"
#include "IMFFormData.h"
#include "Log.h"

namespace http {

   int HTTPPUTHandler::processCommand(coreutils::ZString &request, core::TCPSession &session) {

      HTTPRequest httpRequest(request);

      HTTPSession *httpSession = static_cast<HTTPServer *>(session.server)->httpSessions.findSessionByHeader(httpRequest);

      std::stringstream content;
      HTTPParameters p(httpRequest, session, *httpSession, content, ((HTTPServer *)session.server)->actionList);

      try {
         ((HTTPServer *)(session.server))->pageList.processRequest(p);
	      httpRequest.response.setCode("200");
	      httpRequest.response.setText("OK");
      }
      catch(...) {}

      session.out << httpRequest.response.getResponse(content).str();
//      coreutils::Log(coreutils::LOG_DEBUG_1) << session.out.str();
      return true;
   }

}
