def GET_web(self, url): qs = self.environ.get("QUERY_STRING", "") if qs: url = url + "?" + qs record = self.fetch_arc_record(url) # fake socket to pass to httplib f = StringIO(record.payload) f.makefile = lambda *a: f response = httplib.HTTPResponse(f) response.begin() h = dict(response.getheaders()) content_type = h.get("content-type", "text/plain") self.header("Content-Type", content_type) if 'content-length' in h: self.header('Content-Length', h['content-length']) content = response.read() if content_type.lower().startswith("text/html"): content = self.rewrite_page(url, content) self.header('Content-Length', str(len(content))) elif content_type.lower().startswith("text/css"): content = self.rewrite_css(url, content) self.header('Content-Length', str(len(content))) return [content]
def GET_web(self, url): qs = self.environ.get("QUERY_STRING", "") if qs: url = url + "?" + qs # print url url = re.sub('\s', '%20', url) #print url record = self.fetch_arc_record(url) # fake socket to pass to httplib f = StringIO(record.payload) f.makefile = lambda *a: f response = httplib.HTTPResponse(f) response.begin() h = dict(response.getheaders()) content_type = h.get("content-type", "text/plain") if ';' in content_type: self.charset = content_type.split(';')[1].split('=')[1] self.charset = self.charset.lower() if 'content-length' in h: self.header('Content-Length', h['content-length']) content = response.read() append_line = self.home + "/web/" if content_type.lower().startswith("text/html"): if self.charset: content = content.decode(self.charset, "utf-8") content = self.rewrite_page(url, content, append_line) self.header('Content-Length', str(len(content))) self.header("Content-Type", "text/html; charset=utf-8") elif content_type.lower().startswith("text/css"): if self.charset: content = content.decode(self.charset, "utf-8") content = self.rewrite_css(base_url=url, css=content, append_line=append_line) self.header('Content-Length', str(len(content))) self.header("Content-Type", "text/css; charset=utf-8") #print [content] #sys.exit() return [content]