5 #include "actionrest_p.h" 7 #include "controller.h" 8 #include "dispatcher.h" 61 return d->dispatchRestMethod(c, c->request()->method());
64 ActionRESTPrivate::ActionRESTPrivate(
ActionREST* q) : q_ptr(q)
68 bool ActionRESTPrivate::dispatchRestMethod(
Context *c,
const QString &httpMethod)
const 78 for (
Action *controllerAction : actions) {
79 if (controllerAction->name() == restMethod) {
80 action = controllerAction;
91 if (httpMethod.
compare(u
"OPTIONS") == 0) {
92 ret = returnOptions(c, q->name());
93 }
else if (httpMethod.
compare(u
"HEAD") == 0) {
95 ret = dispatchRestMethod(c, QStringLiteral(
"GET"));
96 }
else if (httpMethod.
compare(u
"not_implemented") != 0) {
98 ret = dispatchRestMethod(c, QStringLiteral(
"not_implemented"));
101 ret = returnNotImplemented(c, q->name());
107 bool ActionRESTPrivate::returnOptions(
Context *c,
const QString &methodName)
const 112 response->
setHeader(QStringLiteral(
"ALLOW"),
113 getAllowedMethods(c->controller(), methodName));
118 bool ActionRESTPrivate::returnNotImplemented(
Context *c,
const QString &methodName)
const 121 response->
setStatus(Response::MethodNotAllowed);
122 response->
setHeader(QStringLiteral(
"ALLOW"),
123 getAllowedMethods(c->controller(), methodName));
135 for (
Action *action : actions) {
143 methods.
append(QStringLiteral(
"HEAD"));
146 methods.
removeAll(QStringLiteral(
"not_implemented"));
150 return methods.
join(QStringLiteral(
", "));
153 #include "moc_actionrest.cpp"
void setContentType(const QString &type)
virtual bool doExecute(Context *c) override
void setHeader(const QString &field, const QString &value)
bool contains(const QString &str, Qt::CaseSensitivity cs) const const
Action * actionFor(const QString &name) const
QString join(const QString &separator) const const
QUrl uriFor(const QString &path=QString(), const QStringList &args=QStringList(), const ParamsMultiMap &queryValues=ParamsMultiMap()) const
QString toString(QUrl::FormattingOptions options) const const
This class represents a Cutelyst Action.
Cutelyst Controller base class
void append(const T &value)
Automated REST Method Dispatching.
bool doExecute(Context *c) override
int removeAll(const T &value)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
The Cutelyst namespace holds all public Cutelyst API.
bool execute(Component *code)
ActionREST(QObject *parent=nullptr)
QString mid(int position, int n) const const
Q_REQUIRED_RESULT QByteArray & body()
void sort(Qt::CaseSensitivity cs)
void setBody(QIODevice *body)
Response * response() const noexcept
ActionList actions() const
int compare(const QString &other, Qt::CaseSensitivity cs) const const
void setStatus(quint16 status) noexcept