Changes between Version 18 and Version 19 of ContributedMiddleware


Ignore:
Timestamp:
08/04/2006 08:50:15 AM (9 years ago)
Author:
dougvanhorn at the gmail dot com
Comment:

I wanted to add the valuable comments from the group thread (now referenced)

Legend:

Unmodified
Added
Removed
Modified
  • ContributedMiddleware

    v18 v19  
    4343
    4444Removes extra whitespace from response content.  It's kind of nice for removing extra line breaks, but it also removes leading spaces.  Probably not too important for most of us, but for the bandwidth conscious it might be helpful.  If you would like to keep your indentions intact, then use `'\s*\n+'` as the regular expression string instead of `'\s*\n+\s*'`.
     45
     46[http://groups.google.com/group/django-developers/browse_thread/thread/fbef71ec761a2220/b2697152b16a7557?lnk=arm Thread]
     47
     48Unfortunately, if you are returning any kind of binary, they get stripped too.  So, to account for that scenario [http://groups.google.com/groups/profile?enc_user=yrG8AxgAAAC4OhwDN-zQr46QcCkWsoHu9lFNBm38GMu1t7hnzP7XlA Nebojša Đorđević] suggested the following:
     49
     50
     51{{{
     52if 'text/html' not in response.headers.get('Content-Type', '').lower(): return response
     53}}}
     54
     55Placed at the beginning of process_response, this will shortcut the middleware for anything ''not'' HTML.
     56
     57Other problems may occur when using this Middleware, such as stripping off meaningful whitespace from Javascript and meaningful whitespace from pre-tags (courtesy of [http://groups.google.com/groups/profile?enc_user=ylvwhxAAAAAdZnZVi3JD5uMPbTyMTmCV Ian Holsman]).  So, this middleware should be considered experimental at best.
     58
     59Unfortunately, I can't seem to edit or remove the attached file, otherwise I might've just done that and slinked away in shame.  :-)
Back to Top