1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #include <anna/core/DataBlock.hpp>
10 #include <anna/core/tracing/Logger.hpp>
11 #include <anna/config/defines.hpp>
12 #include <anna/core/functions.hpp>
14 #include <anna/comm/ClientSocket.hpp>
16 #include <anna/http/Handler.hpp>
17 #include <anna/http/Request.hpp>
18 #include <anna/http/Response.hpp>
19 #include <anna/http/Transport.hpp>
24 http::Handler::~Handler() {
28 //------------------------------------------------------------------------------------------------
29 // (1) Si ha llegado hasta aqui deberia ser porque el mensaje recibido es del protocolo HTTP.
30 //------------------------------------------------------------------------------------------------
31 void http::Handler::apply(comm::ClientSocket& clientSocket, const comm::Message& message)
32 throw(RuntimeException) {
33 if(clientSocket.support(http::Transport::className()) == false) {
35 string msg("anna::http::Handler::apply | Incoming ClientSocket has no support for HTTP | Message: ");
36 msg += functions::asString(message.getBody());
37 Logger::warning(msg, ANNA_FILE_LOCATION);
42 const http::Message& httpMessage = static_cast <const http::Message&>(message); // (1)
45 string msg("apply | ");
47 msg += " | Message: ";
48 msg += httpMessage.asString();
49 Logger::debug(msg, ANNA_FILE_LOCATION);
52 if(httpMessage.getType() == Message::Type::Request) {
54 evRequest(clientSocket, static_cast <const Request&>(httpMessage));
55 } catch(RuntimeException& ex) {
57 Response* response = allocateResponse();
58 response->setStatusCode(400);
59 response->setReasonPhrase(ex.asString());
60 clientSocket.send(*response);
64 evResponse(clientSocket, static_cast <const Response&>(httpMessage));
65 } catch(RuntimeException& ex) {
71 http::Response* http::Handler::allocateResponse()
73 return (a_response == NULL) ? (a_response = new Response) : a_response;