Projet

Général

Profil

Télécharger (944 octets) Statistiques
| Branche: | Révision:

root / larpe / trunk / filter / larpe-filter.py @ 8843f79b

1
from mod_python import apache
2
import re
3

    
4
def outputfilter(filter):
5
	# Only filter html code
6
	if filter.req.content_type is not None:
7
		is_html = re.search('text/html', filter.req.content_type)
8
	if filter.req.content_type is not None and not is_html:
9
		filter.pass_on()
10
	else:
11
		if not hasattr(filter.req, 'temp_doc'): # the start
12
			filter.req.temp_doc = [] # create new attribute to hold document
13
			# If content-length ended up wrong, Gecko browsers truncated data, so
14
			if "Content-Length" in filter.req.headers_out:
15
				del filter.req.headers_out["Content-Length"]
16

    
17
		temp_doc = filter.req.temp_doc
18
		s = filter.read()
19
		while s: # could get '' at any point, but only get None at end
20
			temp_doc.append(s)
21
			s = filter.read()
22

    
23
		if s is None: # the end
24
			temp_doc = ''.join(temp_doc)
25
			#filter.req.set_content_length(len(temp_doc)) # this didn't seem to work
26
			filter.write(temp_doc)
27
			#filter.write(filter.req.uri)
28
			filter.close()
    (1-1/1)