I am using this middleware to make my app restful, but it looks like my form parameters are not coming through:
from google.appengine.ext import webapp
class RestHTTPMiddleware(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
method = webapp.Request(environ).get('_method')
request = Request(environ)
environ['wsgi.input'] = StringIO.StringIO(request.body)
if method:
environ['REQUEST_METHOD'] = method.upper()
return self.app(environ, start_response)
when I submit a form and the debug it using:
def put(self):
logging.debug(self.request.get('description'))
the logger is empty. The put(self) method is being called, I have tested it using the logger and my debug message is shown.
2nd revision:
from google.appengine.ext import webapp
from webob import Request
import logging
import StringIO
class RestHTTPMiddleware(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
request = Request(environ)
environ['wsgi.input'] = StringIO.StringIO(request.body)
method = webapp.Request(environ).get('_method')
if method:
environ['REQUEST_METHOD'] = method.upper()
return self.app(environ, start_response)
Latest changes:
from google.appengine.ext import webapp
from webob import Request
import logging
import StringIO
class RestHTTPMiddleware(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
request = Request(environ)
body = StringIO.StringIO(request.body)
method = webapp.Request(environ).get('_method', None)
if method:
environ['REQUEST_METHOD'] = method.upper()
environ['wsgi.input'] = body
return self.app(environ, start_response)