18 #include "actionrest_p.h"
20 #include "controller.h"
21 #include "dispatcher.h"
26 using namespace Cutelyst;
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"
void setContentType(const QString &type)
virtual bool doExecute(Context *c) override
void setHeader(const QString &field, const QString &value)
ActionList actions() const
bool contains(const QString &str, Qt::CaseSensitivity cs) const
QString join(const QString &separator) const
void setStatus(quint16 status)
QString toString(FormattingOptions options) const
This class represents a Cutelyst Action.
Action * actionFor(const QString &name) const
Cutelyst Controller base class
void append(const T &value)
Automated REST Method Dispatching.
QUrl uriFor(const QString &path=QString(), const QStringList &args=QStringList(), const ParamsMultiMap &queryValues=ParamsMultiMap()) const
bool doExecute(Context *c) override
int removeAll(const T &value)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
bool execute(Component *code)
ActionREST(QObject *parent=nullptr)
Response * response() const
QString mid(int position, int n) const
Q_REQUIRED_RESULT QByteArray & body()
void sort(Qt::CaseSensitivity cs)
void setBody(QIODevice *body)