views:

31

answers:

1

I need to implement a HTTP proxy in Django and my Google safari led me to a project called django-webproxy.

Although no longer maintained, it's quite simple. Most of the logic relies on a simple proxy Middleware class that intercepts all requests to the Django WSGI server and handles it.

If the Middleware returns any data, the WSGI server simply passes it back to the client but if it returns nothing, Django simply handles the request by passing to the other Middleware.

Everything works fine, pretty much, but I need to implement proxy authentication which mean i have to send a 407 status code to the client with a Proxy-Authenticate header. This sin't allowed by Django as it is a hop-by-hop header and Django throws an exception. How can i hack/force/kludge Django into allowing me to send hop-by-hop headers?

FYI, ihe code for the middleware class can be found here.

A: 
from django.core.servers import basehttp

del basehttp._hop_headers['proxy-authenticate']
del basehttp._hop_headers['proxy-authorization']

This worked for me.

Mridang Agarwalla