PATCH method handler on Google AppEngine WebApp2

孤人 提交于 2019-12-05 17:44:24

问题


I tried to use a def patch(): method in my webapp2.RequestHandler to support partial resource updates, but then saw that the allowed methods are frozen in webapp2.py:

allowed_methods = frozenset(('GET', 'POST', 'HEAD', 'OPTIONS', 'PUT',
                             'DELETE', 'TRACE'))

How can I extend webapp2.RequestHandler or modify the WSGIApplication class to allow the PATCH HTTP method when deployed on Google AppEngine?


回答1:


Just use a monkey patch by performing this before creating a WSGIApplication:

allowed_methods = webapp2.WSGIApplication.allowed_methods
new_allowed_methods = allowed_methods.union(('PATCH',))
webapp2.WSGIApplication.allowed_methods = new_allowed_methods

There is a current patch on the webapp2 issue tracker but no one has picked it up.



来源:https://stackoverflow.com/questions/16280496/patch-method-handler-on-google-appengine-webapp2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!