PageRenderTime 428ms CodeModel.GetById 322ms app.highlight 6ms RepoModel.GetById 98ms app.codeStats 0ms

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