Simon Willison’s Weblog

12 items tagged “middleware”

Debugging Django in Production Revisited. Eric Holscher expands his show-technical-errors-to-superusers middleware to only show them to users in the group named “Technical Errors”. # 7th September 2009, 5:21 am

Finding and fixing memory leaks in Python. Using Dozer, a clever piece of WSGI middleware which displays sparklines of Python object counts and allows you to introspect them, using the gc module under the hood. # 22nd April 2009, 12:16 pm

Integrating Facebook Connect with Django in 15 minutes. Django authentication middleware that calls the Facebook REST API using a cookie set by Facebook Connect and checks if that person is your Facebook friend. Despite most of the magic happening on the server you still need Facebook’s JavaScript to set that cookie in the first place. # 17th December 2008, 1:18 pm

csrf_protect.php. A PHP class for applying CSRF protection to existing PHP applications, using output buffering to rewrite any POST forms on a page. Heavily inspired by Django’s CSRF middleware. Tell me if you spot any bugs! # 24th September 2008, 2:52 pm

minidetector. Neat piece of Django middleware that adds a “mobile = True” attribute to the request object if the request’s user-agent matches a list of strings of known low-power browsers in mobiles, PDAs or game consoles. # 15th August 2008, 8:21 am

Super User Conditional Page Exception Reporting. The name is almost as long as the code snippet: this serves Django’s debug page to logged in super-users, falling back to the default 500 template for everyone else. # 31st July 2008, 9:06 pm

mod_rpaf for Apache. A more secure alternative to Django’s equivalent middleware: sets the REMOTE_ADDR of incoming requests from whitelisted load balancers to the X-Forwarded-For header, without any risk that if the load balancers are missing attackers could abuse it to spoof their IP addresses. # 24th June 2008, 5:02 pm

DebugFooter middleware with Pygments sql syntax highlighting. Andreas Marr has enhanced my Django DebugFooter middleware with proper syntax highlighting for the logged SQL. # 14th June 2008, 10:04 am

Debugging Django

I gave a talk on Debugging Django applications at Monday’s inaugural meeting of DJUGL, the London Django Users Group. I wanted to talk about something that wasn’t particularly well documented elsewhere, so I pitched the talk as “Bug Driven Development”—what happens when Test Driven Development goes the way of this unfortunate pony.

The slides [... 1759 words]

django-db-log. Middleware that logs Django exceptions to the database, using a clever scheme based on an MD5 of the traceback text to group duplicate errors in to batches. # 13th May 2008, 8:07 am

Wait For It (via) Neat WSGI middleware from Ian Bicking that launches a thread for every incoming request and watches for slow responses; if something is taking too long it returns a “please wait” page to the user and polls for completion. # 9th June 2007, 4:53 pm

Avoid IE Brokenness When using Vary and Attachments (via) Django middleware that works around a bug in IE where external applications fail to load content that was served with a Vary header. # 9th April 2007, 9:41 am