5#include "actionrest_p.h"
54 :
Action(new ActionRESTPrivate(this), parent)
66 return d->dispatchRestMethod(c, c->
request()->method());
69ActionRESTPrivate::ActionRESTPrivate(
ActionREST *q)
74bool ActionRESTPrivate::dispatchRestMethod(
Context *c,
const QByteArray &httpMethod)
const
84 for (
Action *controllerAction : actions) {
85 if (controllerAction->name() == restMethod) {
86 action = controllerAction;
97 if (httpMethod.
compare(
"OPTIONS") == 0) {
98 ret = returnOptions(c, q->name());
99 }
else if (httpMethod.
compare(
"HEAD") == 0) {
101 ret = dispatchRestMethod(c,
"GET"_qba);
102 }
else if (httpMethod.
compare(
"not_implemented") != 0) {
104 ret = dispatchRestMethod(c,
"not_implemented"_qba);
107 ret = returnNotImplemented(c, q->name());
113bool ActionRESTPrivate::returnOptions(
Context *c,
const QString &methodName)
const
123bool ActionRESTPrivate::returnNotImplemented(
Context *c,
const QString &methodName)
const
126 response->
setStatus(Response::MethodNotAllowed);
128 const QByteArray body =
"Method " + c->
req()->method() +
" not implemented for " +
135 const QString &methodName)
const
138 const QString name = methodName + u
'_';
140 for (
Action *action : actions) {
148 methods.
append(QStringLiteral(
"HEAD"));
151 methods.
removeAll(QStringLiteral(
"not_implemented"));
158#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
QUrl uriFor(const QString &path={}, const QStringList &args={}, const ParamsMultiMap &queryValues={}) const
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)
qsizetype removeAll(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