/src/IndigoRequestHandler.h

https://bitbucket.org/vsemionov/indigo-filer · C Header · 70 lines · 35 code · 9 blank · 26 comment · 0 complexity · a98142c0157fc199cbfc8a7d6cdffdbe MD5 · raw file

  1. /*
  2. * Copyright (C) 2010, Victor Semionov
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright notice,
  10. * this list of conditions and the following disclaimer in the documentation
  11. * and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  14. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  15. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  16. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
  18. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  19. * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  24. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  25. * DAMAGE.
  26. */
  27. #ifndef INDIGOREQUESTHANDLER_H
  28. #define INDIGOREQUESTHANDLER_H
  29. #include "Poco/Net/HTTPRequestHandler.h"
  30. #include "Poco/Net/HTTPServerRequest.h"
  31. #include "Poco/Net/HTTPServerResponse.h"
  32. #include "Poco/Path.h"
  33. using namespace std;
  34. using namespace Poco;
  35. using namespace Poco::Net;
  36. class IndigoRequestHandler: public HTTPRequestHandler
  37. {
  38. public:
  39. IndigoRequestHandler();
  40. void handleRequest(HTTPServerRequest &request, HTTPServerResponse &response);
  41. private:
  42. static Path resolveFSPath(const Path &uriPath);
  43. static void sendFile(HTTPServerResponse &response, const Path &path);
  44. static void sendFile(HTTPServerResponse &response, const string &path);
  45. static void sendDirectoryListing(HTTPServerResponse &response, const string &uri, const vector<string> &entries);
  46. static Path findVirtualIndex();
  47. static void sendVirtualIndex(HTTPServerResponse &response);
  48. static string findDirectoryIndex(const string &base);
  49. static void sendDirectoryIndex(HTTPServerResponse &response, const string &path, const string &uri);
  50. static void redirectToDirectory(HTTPServerResponse &response, const string &uri, bool permanent);
  51. static void logRequest(const HTTPServerRequest &request);
  52. static void sendError(HTTPServerResponse &response, int code);
  53. static void sendMethodNotAllowed(HTTPServerResponse &response);
  54. static void sendRequestURITooLong(HTTPServerResponse &response);
  55. static void sendBadRequest(HTTPServerResponse &response);
  56. static void sendNotImplemented(HTTPServerResponse &response);
  57. static void sendNotFound(HTTPServerResponse &response);
  58. static void sendForbidden(HTTPServerResponse &response);
  59. static void sendInternalServerError(HTTPServerResponse &response);
  60. };
  61. #endif //INDIGOREQUESTHANDLER_H