18 #include "actionrest_p.h"
20 #include "controller.h"
21 #include "dispatcher.h"
74 return d->dispatchRestMethod(c, c->request()->method());
77 ActionRESTPrivate::ActionRESTPrivate(
ActionREST* q) : q_ptr(q)
81 bool ActionRESTPrivate::dispatchRestMethod(
Context *c,
const QString &httpMethod)
const
91 for (
Action *controllerAction : actions) {
92 if (controllerAction->name() == restMethod) {
93 action = controllerAction;
105 ret = returnOptions(c, q->name());
108 ret = dispatchRestMethod(c, QStringLiteral(
"GET"));
111 ret = dispatchRestMethod(c, QStringLiteral(
"not_implemented"));
114 ret = returnNotImplemented(c, q->name());
120 bool ActionRESTPrivate::returnOptions(
Context *c,
const QString &methodName)
const
125 response->
setHeader(QStringLiteral(
"ALLOW"),
126 getAllowedMethods(c->controller(), methodName));
131 bool ActionRESTPrivate::returnNotImplemented(
Context *c,
const QString &methodName)
const
134 response->
setStatus(Response::MethodNotAllowed);
135 response->
setHeader(QStringLiteral(
"ALLOW"),
136 getAllowedMethods(c->controller(), methodName));
148 for (
Action *action : actions) {
155 if (methods.
contains(QStringLiteral(
"GET"))) {
156 methods.
append(QStringLiteral(
"HEAD"));
159 methods.
removeAll(QStringLiteral(
"not_implemented"));
163 return methods.
join(QStringLiteral(
", "));
166 #include "moc_actionrest.cpp"
Automated REST Method Dispatching.
bool doExecute(Context *c) override
ActionREST(QObject *parent=nullptr)
This class represents a Cutelyst Action.
virtual bool doExecute(Context *c) override
QUrl uriFor(const QString &path=QString(), const QStringList &args=QStringList(), const ParamsMultiMap &queryValues=ParamsMultiMap()) const
Response * response() const
bool execute(Component *code)
Cutelyst Controller base class
Action * actionFor(const QString &name) const
ActionList actions() const
void setBody(QIODevice *body)
void setHeader(const QString &field, const QString &value)
void setStatus(quint16 status)
Q_REQUIRED_RESULT QByteArray & body()
void setContentType(const QString &type)
The Cutelyst namespace holds all public Cutelyst API.
void append(const T &value)
int removeAll(const T &value)
QString mid(int position, int n) const const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
bool contains(const QString &str, Qt::CaseSensitivity cs) const const
QString join(const QString &separator) const const
void sort(Qt::CaseSensitivity cs)
QString toString(QUrl::FormattingOptions options) const const