@@ -93,14 +93,6 @@ def dispatch_request(self, *args, **kwargs):
93
93
# Flask should ensure this is assersion never fails
94
94
assert meth is not None , f"Unimplemented method { request .method !r} "
95
95
96
- # Inject request arguments if an args schema is defined
97
- if self .get_args ():
98
- meth = use_args (self .get_args ())(meth )
99
-
100
- # Marhal response if a response schema is defines
101
- if self .get_schema ():
102
- meth = marshal_with (self .get_schema ())(meth )
103
-
104
96
# Generate basic response
105
97
return self .represent_response (meth (* args , ** kwargs ))
106
98
@@ -145,6 +137,14 @@ def dispatch_request(self, *args, **kwargs):
145
137
if request .method != "POST" :
146
138
return View .dispatch_request (self , * args , ** kwargs )
147
139
140
+ # Inject request arguments if an args schema is defined
141
+ if self .get_args ():
142
+ meth = use_args (self .get_args ())(meth )
143
+
144
+ # Marhal response if a response schema is defines
145
+ if self .get_schema ():
146
+ meth = marshal_with (self .get_schema ())(meth )
147
+
148
148
# Make a task out of the views `post` method
149
149
task = taskify (meth )(* args , ** kwargs )
150
150
@@ -179,10 +179,29 @@ def get_args(cls):
179
179
return cls .schema
180
180
181
181
def dispatch_request (self , * args , ** kwargs ):
182
- if request .method in ("POST" , "PUT" , "DELETE" , "PATCH" ):
183
- # FIXME: Sketchy as this breaks if the response is a generator/loop
184
- resp = View .dispatch_request (self , * args , ** kwargs )
182
+ meth = getattr (self , request .method .lower (), None )
185
183
184
+ # If the request method is HEAD and we don't have a handler for it
185
+ # retry with GET.
186
+ if meth is None and request .method == "HEAD" :
187
+ meth = getattr (self , "get" , None )
188
+
189
+ # Flask should ensure this is assersion never fails
190
+ assert meth is not None , f"Unimplemented method { request .method !r} "
191
+
192
+ # Inject request arguments if an args schema is defined
193
+ if request .method in ("POST" , "PUT" , "PATCH" ) and self .get_args ():
194
+ meth = use_args (self .get_args ())(meth )
195
+
196
+ # Marhal response if a response schema is defines
197
+ if self .get_schema ():
198
+ meth = marshal_with (self .get_schema ())(meth )
199
+
200
+ # Generate basic response
201
+ resp = self .represent_response (meth (* args , ** kwargs ))
202
+
203
+ # Emit property event
204
+ if request .method in ("POST" , "PUT" , "DELETE" , "PATCH" ):
186
205
property_value = self .get_value ()
187
206
property_name = getattr (self , "endpoint" , None ) or getattr (
188
207
self , "__name__" , "unknown"
@@ -193,6 +212,4 @@ def dispatch_request(self, *args, **kwargs):
193
212
PropertyStatusEvent (property_name ), property_value ,
194
213
)
195
214
196
- return resp
197
-
198
- return View .dispatch_request (self , * args , ** kwargs )
215
+ return resp
0 commit comments