You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've read IMiddleware docs in official docs. I should be able to implement this interface and extend the TrackingMiddleware with my own implementation.
Please describe the actual behaviour
I defined a MyTrackingMiddleware class and used that in my plugin.py like this:
from ckan.config.middleware.common_middleware import TrackingMiddleware
import urllib2
import hashlib
import sqlalchemy as sa
import pylons.config as config
class MyTrackingMiddleware(TrackingMiddleware):
def __init__(self, app, config):
self.app = app
self.config = config
def __call__(self, environ, start_response):
super(MyTrackingMiddleware, self).__call__(environ, start_response)
if path == '/_tracking' and method == 'GET':
print("===============YOUR METHOD IS GET=================")
'''
Handle get request
'''
return self.app(environ, start_response)
class MyPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IMiddleware, inherit=True)
def make_middleware(self, app, config):
app = MyTrackingMiddleware(app, config)
return app
I visited some package, MyTrackingMiddleware has never received requests to /_tracking. All the paths I got from environ are package urls. I think it is because the environ I passed in MyTrackingMiddleware is not within the global context. Instead, the environ I got is from local context. However, I don't know how to pass the global environ.
What steps can be taken to reproduce the issue?
My steps has already provided in the last section.
The text was updated successfully, but these errors were encountered:
It looks like the standard TrackingMiddleware intercepts all POST requests to `/_tracking'. As a quick hack you could disable the TrackingMiddleware in your copy of ckan to see if that resolves the issue.
If that does work, we could change the middleware order so that custom middleware comes earlier in the stack. We'd have to check if that would break any existing middleware plugins of course.
@wardi Thanks for your advice. I disabled tracking_enabled in dev.ini, at least I won't see request being sent to /_tracking, so that it gives me the flexibility to handle tracking on application level.
LingboTang
changed the title
How to extend TrackingMiddleware in my own extension/plugin
How to extend TrackingMiddleware in customized extension/plugin
Sep 11, 2018
CKAN Version if known (or site URL)
2.7.3
Please describe the expected behaviour
I've read IMiddleware docs in official docs. I should be able to implement this interface and extend the
TrackingMiddleware
with my own implementation.Please describe the actual behaviour
I defined a
MyTrackingMiddleware
class and used that in myplugin.py
like this:I visited some package,
MyTrackingMiddleware
has never received requests to/_tracking
. All the paths I got from environ are package urls. I think it is because theenviron
I passed inMyTrackingMiddleware
is not within the global context. Instead, theenviron
I got is from local context. However, I don't know how to pass the globalenviron
.What steps can be taken to reproduce the issue?
My steps has already provided in the last section.
The text was updated successfully, but these errors were encountered: