MethodOverride class
Lets a plain HTML form reach a Route.put, Route.patch or
Route.delete route. A form can only send GET or POST, so it sends
POST with a _method field:
<form method="POST" action="/posts/5">
<input type="hidden" name="_method" value="DELETE">
</form>
Add it to globalMiddleware. It is off when it is not there.
AppConfig(
globalMiddleware: <dynamic>[const MethodOverride()],
);
Only a POST request changes, and only to PUT, PATCH or DELETE (in any
case). Any other _method value is ignored. req.method gives the
new method. CsrfMiddleware still checks the request, because it was
sent as POST.
The route is found before middleware runs, so Dox reads the body of a
POST request first and looks at _method there. A POST to a path
with no route for any method gets 404 with no body read. The middleware
itself does nothing; it only turns this on. It works only in
AppConfig.globalMiddleware, not on a router or a route.
With header on, a POST can also ask for the method with the
X-HTTP-Method-Override header, like a JS client that can not send
PUT. The header wins over _method. It is off by default.
globalMiddleware: <dynamic>[const MethodOverride(header: true)],
- Implemented types
Constructors
- MethodOverride({bool header = false})
-
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- header → bool
-
also read the headerName header
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
handle(
IDoxRequest req) → IDoxRequest -
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
enabledIn(
List global) → bool -
true when
globalhas a MethodOverride. checked again only when the list changes. -
from(
Map< String, dynamic> body) → String? -
The method
bodyasks for with_method, or null when it asks for none or for one that is not PUT, PATCH or DELETE. -
fromHeader(
String? value) → String? -
The method the headerName header
valueasks for, like from. Null when no MethodOverride in the global middleware has header on.
Constants
- field → const String
- the form field name
- headerName → const String
- the header name, read only when header is on