5 #include "actionrest_p.h" 7 #include "controller.h" 8 #include "dispatcher.h" 54 :
Action(new ActionRESTPrivate(this), parent)
66 return d->dispatchRestMethod(c, c->
request()->method());
69 ActionRESTPrivate::ActionRESTPrivate(
ActionREST *q)
74 bool 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());
113 bool ActionRESTPrivate::returnOptions(
Context *c,
const QString &methodName)
const 123 bool 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"
bool contains(QLatin1String str, Qt::CaseSensitivity cs) const const
bool doExecute(Context *c) override
qsizetype removeDuplicates()
qsizetype size() const const
QUrl uriFor(const QString &path={}, const QStringList &args={}, const ParamsMultiMap &queryValues={}) const
QString join(QStringView separator) const const
QString toString(QUrl::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.
void append(QList::parameter_type value)
Automated REST method dispatching.
bool doExecute(Context *c) override
qsizetype removeAll(const AT &t)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
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 sort(Qt::CaseSensitivity cs)
Action * actionFor(QStringView name) const
void setBody(QIODevice *body)
Response * response() const noexcept
void setStatus(quint16 status) noexcept
ActionList actions() const noexcept
void setHeader(const QByteArray &key, const QByteArray &value)