00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "AllowNothingService.hpp"
00011 #include <pion/PionConfig.hpp>
00012 #include <pion/net/HTTPResponseWriter.hpp>
00013
00014 using namespace pion;
00015 using namespace pion::net;
00016
00017 namespace pion {
00018 namespace plugins {
00019
00020
00021 void AllowNothingService::operator()(HTTPRequestPtr& request, TCPConnectionPtr& tcp_conn)
00022 {
00023 static const std::string DENY_HTML = "<html><body>No, you can't.</body></html>";
00024 HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request,
00025 boost::bind(&TCPConnection::finish, tcp_conn)));
00026 writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_METHOD_NOT_ALLOWED);
00027 writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_METHOD_NOT_ALLOWED);
00028
00029
00030
00031
00032
00033 writer->getResponse().addHeader("Allow", "GET");
00034
00035 writer->writeNoCopy(DENY_HTML);
00036 writer->writeNoCopy(HTTPTypes::STRING_CRLF);
00037 writer->writeNoCopy(HTTPTypes::STRING_CRLF);
00038 writer->send();
00039 }
00040
00041
00042 }
00043 }
00044
00045
00047 extern "C" PION_SERVICE_API pion::plugins::AllowNothingService *pion_create_AllowNothingService(void)
00048 {
00049 return new pion::plugins::AllowNothingService();
00050 }
00051
00053 extern "C" PION_SERVICE_API void pion_destroy_AllowNothingService(pion::plugins::AllowNothingService *service_ptr)
00054 {
00055 delete service_ptr;
00056 }