5 #include "actionrest_p.h"
7 #include "controller.h"
8 #include "dispatcher.h"
14 using namespace Qt::StringLiterals;
55 :
Action(new ActionRESTPrivate(this), parent)
67 return d->dispatchRestMethod(c, c->
request()->method());
70 ActionRESTPrivate::ActionRESTPrivate(
ActionREST *q)
75 bool ActionRESTPrivate::dispatchRestMethod(
Context *c,
const QByteArray &httpMethod)
const
85 for (
Action *controllerAction : actions) {
86 if (controllerAction->name() == restMethod) {
87 action = controllerAction;
98 if (httpMethod.
compare(
"OPTIONS") == 0) {
99 ret = returnOptions(c, q->name());
100 }
else if (httpMethod.
compare(
"HEAD") == 0) {
102 ret = dispatchRestMethod(c,
"GET"_qba);
103 }
else if (httpMethod.
compare(
"not_implemented") != 0) {
105 ret = dispatchRestMethod(c,
"not_implemented"_qba);
108 ret = returnNotImplemented(c, q->name());
114 bool ActionRESTPrivate::returnOptions(
Context *c,
const QString &methodName)
const
124 bool ActionRESTPrivate::returnNotImplemented(
Context *c,
const QString &methodName)
const
127 response->
setStatus(Response::MethodNotAllowed);
130 const QByteArray body =
"Method " + c->
req()->method() +
" not implemented for " +
137 const QString &methodName)
const
140 const QString name = methodName + u
'_';
142 for (
Action *action : actions) {
150 methods.
append(QStringLiteral(
"HEAD"));
160 #include "moc_actionrest.cpp"
Automated REST method dispatching.
bool doExecute(Context *c) override
ActionREST(QObject *parent=nullptr)
This class represents a Cutelyst Action.
bool doExecute(Context *c) override
QString name() const noexcept
bool execute(Component *code)
Response * response() const noexcept
Cutelyst Controller base class.
ActionList actions() const noexcept
Action * actionFor(QStringView name) const
void setContentType(const QByteArray &type)
void setStatus(quint16 status) noexcept
void setHeader(const QByteArray &key, const QByteArray &value)
void setBody(QIODevice *body)
The Cutelyst namespace holds all public Cutelyst API.
int compare(QByteArrayView bv, Qt::CaseSensitivity cs) const const
void append(QList::parameter_type value)
bool removeOne(const AT &t)
QString fromLatin1(QByteArrayView str)
QString mid(qsizetype position, qsizetype n) const const
qsizetype size() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QByteArray toLatin1() const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
QString join(QChar separator) const const
qsizetype removeDuplicates()
void sort(Qt::CaseSensitivity cs)
QString toString(QUrl::FormattingOptions options) const const