5 #include "actionrest_p.h" 7 #include "controller.h" 8 #include "dispatcher.h" 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"_ba);
103 }
else if (httpMethod.
compare(
"not_implemented") != 0) {
105 ret = dispatchRestMethod(c,
"not_implemented"_ba);
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"
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
bool doExecute(Context *c) override
qsizetype removeDuplicates()
qsizetype size() const const
QString join(QChar separator) const const
QString toString(FormattingOptions options) const const
void setContentType(const QByteArray &type)
This class represents a Cutelyst Action.
int compare(QByteArrayView bv, Qt::CaseSensitivity cs) const const
Cutelyst Controller base class.
Automated REST method dispatching.
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
bool doExecute(Context *c) override
QString name() const noexcept
The Cutelyst namespace holds all public Cutelyst API.
bool execute(Component *code)
ActionREST(QObject *parent=nullptr)
QString fromLatin1(QByteArrayView str)
QByteArray toLatin1() const const
QString mid(qsizetype position, qsizetype n) const const
void append(QList< T > &&value)
void sort(Qt::CaseSensitivity cs)
Action * actionFor(QStringView name) const
void setBody(QIODevice *body)
Response * response() const noexcept
void setStatus(quint16 status) noexcept
bool removeOne(const AT &t)
ActionList actions() const noexcept
void setHeader(const QByteArray &key, const QByteArray &value)