python - Tornado: Are there Request Filters? -


i looking @ tornado app , wondering how perform use case. need intercept every request before dispatching url handler , possibly return redirect. there way using tornado?

i wondering if tornado has concept of servlet filter. looks maybe input modifier decode_argumentdoes this? seems bit of hack filter request using method, haven't found else in documentation.

you have al least 3 options:

  • use requesthandler.prepare() kamushin said.

  • as said in this tornado issue comment:

    you can hook middleware, actually. httpserver request handlers callable objects (function, methods, or objects implement __call__). can write own handler passes on requests application

(example)

my_app = tornado.web.application(...)  def middleware(request):     # whatever transformation want here     my_app(request)  if __name__ == '__main__':     http_server = tornado.httpserver.httpserver(middleware)     # ... 

but notice that:

since tornado request handling can asynchronous, can't modify response in middleware, can @ least work request.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -