QDjango
QDjangoHttpController.h
00001 /*
00002  * Copyright (C) 2010-2012 Jeremy Lainé
00003  * Contact: http://code.google.com/p/qdjango/
00004  *
00005  * This file is part of the QDjango Library.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  */
00017 
00018 #ifndef QDJANGO_HTTP_CONTROLLER_H
00019 #define QDJANGO_HTTP_CONTROLLER_H
00020 
00021 #include <QDateTime>
00022 #include <QString>
00023 
00024 #include "QDjangoHttp_p.h"
00025 
00026 class QDjangoHttpRequest;
00027 class QDjangoHttpResponse;
00028 class QUrl;
00029 
00034 class QDJANGO_EXPORT QDjangoHttpController
00035 {
00036 public:
00037     // get basic authorization credentials
00038     static bool getBasicAuth(const QDjangoHttpRequest &request, QString &username, QString &password);
00039 
00040     // date / time handling
00041     static QString httpDateTime(const QDateTime &dt);
00042     static QDateTime httpDateTime(const QString &str);
00043 
00044     // common responses
00045     static QDjangoHttpResponse *serveAuthorizationRequired(const QDjangoHttpRequest &request, const QString &realm = QString("Secure Area"));
00046     static QDjangoHttpResponse *serveBadRequest(const QDjangoHttpRequest &request);
00047     static QDjangoHttpResponse *serveInternalServerError(const QDjangoHttpRequest &request);
00048     static QDjangoHttpResponse *serveNotFound(const QDjangoHttpRequest &request);
00049     static QDjangoHttpResponse *serveRedirect(const QDjangoHttpRequest &request, const QUrl &url, bool permanent = false);
00050     static QDjangoHttpResponse *serveStatic(const QDjangoHttpRequest &request, const QString &filePath, const QDateTime &expires = QDateTime());
00051 
00052 private:
00053     static QDjangoHttpResponse *serveError(const QDjangoHttpRequest &request, int code, const QString &text);
00054 };
00055 
00056 #endif
 All Classes Functions Typedefs Enumerations Enumerator Properties