5 #include "actionrest_p.h" 7 #include "controller.h" 8 #include "dispatcher.h" 52 :
Action(new ActionRESTPrivate(this), parent)
64 return d->dispatchRestMethod(c, c->request()->method());
67 ActionRESTPrivate::ActionRESTPrivate(
ActionREST *q)
72 bool ActionRESTPrivate::dispatchRestMethod(
Context *c,
const QString &httpMethod)
const 75 const QString restMethod = q->name() + u
'_' + httpMethod;
82 for (
Action *controllerAction : actions) {
83 if (controllerAction->name() == restMethod) {
84 action = controllerAction;
95 if (httpMethod.compare(u
"OPTIONS") == 0) {
96 ret = returnOptions(c, q->name());
97 }
else if (httpMethod.compare(u
"HEAD") == 0) {
99 ret = dispatchRestMethod(c, QStringLiteral(
"GET"));
100 }
else if (httpMethod.compare(u
"not_implemented") != 0) {
102 ret = dispatchRestMethod(c, QStringLiteral(
"not_implemented"));
105 ret = returnNotImplemented(c, q->name());
111 bool ActionRESTPrivate::returnOptions(
Context *c,
const QString &methodName)
const 116 response->
setHeader(QStringLiteral(
"ALLOW"), getAllowedMethods(c->controller(), methodName));
121 bool ActionRESTPrivate::returnNotImplemented(
Context *c,
const QString &methodName)
const 124 response->
setStatus(Response::MethodNotAllowed);
125 response->
setHeader(QStringLiteral(
"ALLOW"), getAllowedMethods(c->controller(), methodName));
133 const QString &methodName)
const 136 const QString name = methodName + u
'_';
138 for (
Action *action : actions) {
146 methods.
append(QStringLiteral(
"HEAD"));
149 methods.
removeAll(QStringLiteral(
"not_implemented"));
153 return methods.
join(u
", ");
156 #include "moc_actionrest.cpp" bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
void setContentType(const QString &type)
virtual bool doExecute(Context *c) override
void setHeader(const QString &field, const QString &value)
qsizetype removeDuplicates()
qsizetype size() const const
QString join(QChar separator) const const
Action * actionFor(const QString &name) const
QUrl uriFor(const QString &path=QString(), const QStringList &args=QStringList(), const ParamsMultiMap &queryValues=ParamsMultiMap()) const
QString toString(FormattingOptions options) const const
This class represents a Cutelyst Action.
Cutelyst Controller base class
Automated REST Method Dispatching.
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
bool doExecute(Context *c) override
qsizetype removeAll(const AT &t)
The Cutelyst namespace holds all public Cutelyst API.
bool execute(Component *code)
ActionREST(QObject *parent=nullptr)
QString mid(qsizetype position, qsizetype n) const const
void append(QList< T > &&value)
Q_REQUIRED_RESULT QByteArray & body()
void sort(Qt::CaseSensitivity cs)
void setBody(QIODevice *body)
Response * response() const noexcept
ActionList actions() const
void setStatus(quint16 status) noexcept