Changeset 43:70cd01599f4e
- Timestamp:
- 11/19/06 09:34:03
(2 years ago)
- Author:
- Allan Saddi <allan@saddi.com>
- branch:
- default
- convert_revision:
- svn:46762da8-4eb7-0310-94e9-d918b60927c8/flup/trunk@2106
- Message:
Change mime-type matching algorithm in GzipMiddleware?.
Strip parameters (e.g. "encoding") and accept a list of
regexps. By default, compress 'text/.*' mime-types.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r42 |
r43 |
|
| | 1 | 2006-11-19 Allan Saddi <asaddi@europa.saddi.net> |
|---|
| | 2 | |
|---|
| | 3 | * Change mime-type matching algorithm in GzipMiddleware. |
|---|
| | 4 | Strip parameters (e.g. "encoding") and accept a list of |
|---|
| | 5 | regexps. By default, compress 'text/.*' mime-types. |
|---|
| | 6 | |
|---|
| 1 | 7 | 2006-11-10 Allan Saddi <asaddi@europa.saddi.net> |
|---|
| 2 | 8 | |
|---|
| r1 |
r43 |
|
| 31 | 31 | import time |
|---|
| 32 | 32 | import zlib |
|---|
| | 33 | import re |
|---|
| 33 | 34 | |
|---|
| 34 | 35 | __all__ = ['GzipMiddleware'] |
|---|
| … | … | |
| 157 | 158 | for name,value in headers: |
|---|
| 158 | 159 | name = name.lower() |
|---|
| 159 | | if name == 'content-type' and value in self._mimeTypes: |
|---|
| 160 | | self.gzipOk = True |
|---|
| | 160 | if name == 'content-type': |
|---|
| | 161 | value = value.split(';')[0].strip() |
|---|
| | 162 | for p in self._mimeTypes: |
|---|
| | 163 | if p.match(value) is not None: |
|---|
| | 164 | self.gzipOk = True |
|---|
| | 165 | break |
|---|
| 161 | 166 | elif name == 'content-encoding': |
|---|
| 162 | 167 | self.gzipOk = False |
|---|
| … | … | |
| 194 | 199 | def __init__(self, application, mimeTypes=None, compresslevel=9): |
|---|
| 195 | 200 | if mimeTypes is None: |
|---|
| 196 | | mimeTypes = ['text/html'] |
|---|
| | 201 | mimeTypes = ['text/.*'] |
|---|
| 197 | 202 | |
|---|
| 198 | 203 | self._application = application |
|---|
| 199 | | self._mimeTypes = mimeTypes |
|---|
| | 204 | self._mimeTypes = [re.compile(m) for m in mimeTypes] |
|---|
| 200 | 205 | self._compresslevel = compresslevel |
|---|
| 201 | 206 | |
|---|