CARVIEW |
Select Language
HTTP/2 200
server: nginx
content-type: text/html;charset=utf-8
cache-control: must-revalidate
expires: Fri, 01 Jan 1999 00:00:00 GMT
set-cookie: trac_form_token=95ba0375212542b42790cc19; HttpOnly; Path=/; Secure
set-cookie: trac_session=aa6dee558b598c19d86b1c2d; expires=Tue, 21 Oct 2025 13:15:11 GMT; HttpOnly; Path=/; Secure
strict-transport-security: max-age=31536000; includeSubDomains; preload
permissions-policy: interest-cohort=()
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
accept-ranges: bytes
via: 1.1 varnish, 1.1 varnish
date: Wed, 23 Jul 2025 13:15:11 GMT
x-served-by: cache-fra-eddf8230124-FRA, cache-bom-vanm7210057-BOM
x-cache: MISS, MISS
x-cache-hits: 0, 0
x-timer: S1753276511.276627,VS0,VE284
vary: Accept-Encoding
StripWhitespaceMiddleware – Django
Back to Top
Django
The web framework for perfectionists with deadlines.
Issues
Strip Whitespace Middleware
""" Tightens up response content by removed superflous line breaks and whitespace. By Doug Van Horn ---- CHANGES ---- v1.1 - 31st May 2011 Cal Leeming [Simplicity Media Ltd] Modified regex to strip leading/trailing white space from every line, not just those with blank \n. ---- TODO ---- * Ensure whitespace isn't stripped from within <pre> or <code> or <textarea> tags. """ import re class StripWhitespaceMiddleware(object): """ Strips leading and trailing whitespace from response content. """ def __init__(self): self.whitespace = re.compile('^\s*\n', re.MULTILINE) #self.whitespace_lead = re.compile('^\s+', re.MULTILINE) #self.whitespace_trail = re.compile('\s+$', re.MULTILINE) def process_response(self, request, response): if "text" in response['Content-Type']: #Use next line instead to avoid failure on cached / HTTP 304 NOT MODIFIED responses without Content-Type #if response.status_code == 200 and "text" in response['Content-Type']: if hasattr(self, 'whitespace_lead'): response.content = self.whitespace_lead.sub('', response.content) if hasattr(self, 'whitespace_trail'): response.content = self.whitespace_trail.sub('\n', response.content) if hasattr(self, 'whitespace'): response.content = self.whitespace.sub('', response.content) return response else: return response
Last modified
9 years ago
Last modified on Oct 26, 2016, 10:30:08 AM
Note:
See TracWiki
for help on using the wiki.
Download in other formats:
Django Links
Learn More
Get Involved
Follow Us
- Hosting by In-kind donors
- Design by Threespot &
© 2005-2025 Django SoftwareFoundation unless otherwise noted. Django is a registered trademark of the Django Software Foundation.