mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-25 09:18:54 -05:00
Web API: send API documentation if path is invalid
This commit is contained in:
parent
7fa26835bd
commit
1b5f944302
@ -8,6 +8,8 @@
|
|||||||
#ifndef HTTPSERVER_HTTPDOCROOTSETTINGS_H_
|
#ifndef HTTPSERVER_HTTPDOCROOTSETTINGS_H_
|
||||||
#define HTTPSERVER_HTTPDOCROOTSETTINGS_H_
|
#define HTTPSERVER_HTTPDOCROOTSETTINGS_H_
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
namespace qtwebapp {
|
namespace qtwebapp {
|
||||||
|
|
||||||
struct HttpDocrootSettings
|
struct HttpDocrootSettings
|
||||||
|
@ -61,7 +61,13 @@ StaticFileController::StaticFileController(const HttpDocrootSettings& settings,
|
|||||||
|
|
||||||
void StaticFileController::service(HttpRequest& request, HttpResponse& response)
|
void StaticFileController::service(HttpRequest& request, HttpResponse& response)
|
||||||
{
|
{
|
||||||
QByteArray path=request.getPath();
|
QByteArray path = request.getPath();
|
||||||
|
service(path, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StaticFileController::service(QByteArray& path, HttpResponse& response)
|
||||||
|
{
|
||||||
|
//QByteArray path=request.getPath();
|
||||||
// Check if we have the file in cache
|
// Check if we have the file in cache
|
||||||
qint64 now=QDateTime::currentMSecsSinceEpoch();
|
qint64 now=QDateTime::currentMSecsSinceEpoch();
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
@ -114,7 +120,8 @@ void StaticFileController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
entry->created=now;
|
entry->created=now;
|
||||||
entry->filename=path;
|
entry->filename=path;
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
cache.insert(request.getPath(),entry,entry->document.size());
|
//cache.insert(request.getPath(),entry,entry->document.size());
|
||||||
|
cache.insert(path,entry,entry->document.size());
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -55,9 +55,12 @@ public:
|
|||||||
/** Constructor with settings structure */
|
/** Constructor with settings structure */
|
||||||
StaticFileController(const HttpDocrootSettings& settings, QObject* parent = NULL);
|
StaticFileController(const HttpDocrootSettings& settings, QObject* parent = NULL);
|
||||||
|
|
||||||
/** Generates the response */
|
/** Generates the response from HTTP request */
|
||||||
void service(HttpRequest& request, HttpResponse& response);
|
void service(HttpRequest& request, HttpResponse& response);
|
||||||
|
|
||||||
|
/** Generates the response directly from the path */
|
||||||
|
void service(QByteArray& path, HttpResponse& response);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/** Encoding of text files */
|
/** Encoding of text files */
|
||||||
|
@ -234,9 +234,16 @@ endif (BUILD_DEBIAN)
|
|||||||
add_definitions(${QT_DEFINITIONS})
|
add_definitions(${QT_DEFINITIONS})
|
||||||
add_definitions(-DQT_SHARED)
|
add_definitions(-DQT_SHARED)
|
||||||
|
|
||||||
|
set(sdrbase_RESOURCES
|
||||||
|
resources/res.qrc
|
||||||
|
)
|
||||||
|
|
||||||
|
qt5_add_resources(sdrbase_RESOURCES_RCC ${sdrbase_RESOURCES})
|
||||||
|
|
||||||
add_library(sdrbase SHARED
|
add_library(sdrbase SHARED
|
||||||
${sdrbase_SOURCES}
|
${sdrbase_SOURCES}
|
||||||
${sdrbase_HEADERS_MOC}
|
${sdrbase_HEADERS_MOC}
|
||||||
|
${sdrbase_RESOURCES_RCC}
|
||||||
)
|
)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
|
9045
sdrbase/resources/index.html
Normal file
9045
sdrbase/resources/index.html
Normal file
File diff suppressed because one or more lines are too long
5
sdrbase/resources/res.qrc
Normal file
5
sdrbase/resources/res.qrc
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>index.html</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
@ -200,5 +200,7 @@ HEADERS += audio/audiodeviceinfo.h\
|
|||||||
LIBS += -L../httpserver/$${build_subdir} -lhttpserver
|
LIBS += -L../httpserver/$${build_subdir} -lhttpserver
|
||||||
LIBS += -L../swagger/$${build_subdir} -lswagger
|
LIBS += -L../swagger/$${build_subdir} -lswagger
|
||||||
|
|
||||||
|
RESOURCES = resources/res.qrc
|
||||||
|
|
||||||
CONFIG(ANDROID):CONFIG += mobility
|
CONFIG(ANDROID):CONFIG += mobility
|
||||||
CONFIG(ANDROID):MOBILITY =
|
CONFIG(ANDROID):MOBILITY =
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "httpdocrootsettings.h"
|
||||||
#include "webapirequestmapper.h"
|
#include "webapirequestmapper.h"
|
||||||
#include "SWGInstanceSummaryResponse.h"
|
#include "SWGInstanceSummaryResponse.h"
|
||||||
#include "SWGErrorResponse.h"
|
#include "SWGErrorResponse.h"
|
||||||
@ -23,7 +24,16 @@
|
|||||||
WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) :
|
WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) :
|
||||||
HttpRequestHandler(parent),
|
HttpRequestHandler(parent),
|
||||||
m_adapter(0)
|
m_adapter(0)
|
||||||
{ }
|
{
|
||||||
|
qtwebapp::HttpDocrootSettings docrootSettings;
|
||||||
|
docrootSettings.path = ":/";
|
||||||
|
m_staticFileController = new qtwebapp::StaticFileController(docrootSettings, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
WebAPIRequestMapper::~WebAPIRequestMapper()
|
||||||
|
{
|
||||||
|
delete m_staticFileController;
|
||||||
|
}
|
||||||
|
|
||||||
void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
||||||
{
|
{
|
||||||
@ -61,7 +71,9 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
response.setStatus(404,"Not found");
|
QByteArray path = "/";
|
||||||
|
m_staticFileController->service(path, response);
|
||||||
|
//response.setStatus(404,"Not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,17 +22,20 @@
|
|||||||
#include "httprequesthandler.h"
|
#include "httprequesthandler.h"
|
||||||
#include "httprequest.h"
|
#include "httprequest.h"
|
||||||
#include "httpresponse.h"
|
#include "httpresponse.h"
|
||||||
|
#include "staticfilecontroller.h"
|
||||||
#include "webapiadapterinterface.h"
|
#include "webapiadapterinterface.h"
|
||||||
|
|
||||||
class WebAPIRequestMapper : public qtwebapp::HttpRequestHandler {
|
class WebAPIRequestMapper : public qtwebapp::HttpRequestHandler {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
WebAPIRequestMapper(QObject* parent=0);
|
WebAPIRequestMapper(QObject* parent=0);
|
||||||
|
~WebAPIRequestMapper();
|
||||||
void service(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
void service(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||||
void setAdapter(WebAPIAdapterInterface *adapter) { m_adapter = adapter; }
|
void setAdapter(WebAPIAdapterInterface *adapter) { m_adapter = adapter; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WebAPIAdapterInterface *m_adapter;
|
WebAPIAdapterInterface *m_adapter;
|
||||||
|
qtwebapp::StaticFileController *m_staticFileController;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SDRBASE_WEBAPI_WEBAPIREQUESTMAPPER_H_ */
|
#endif /* SDRBASE_WEBAPI_WEBAPIREQUESTMAPPER_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user