

def on_response(self, resp, req):
    ctype = resp.headers.iget('content-type')
    if (not ctype):
        return
    ctype = ctype.split(';', 1)[0]
    if (ctype in HTML_CTYPES):
        body = resp.body_string()
        html = lxml.html.fromstring(body)
        html.rewrite_links(self.rewrite_link)
        old_base = html.find('.//base')
        base = etree.Element('base')
        base.attrib['href'] = self.absolute_path
        if (not old_base):
            head = html.find('.//head')
            head.append(base)
        rewritten_body = lxml.html.tostring(html)
        try:
            resp.headers.ipop('content-length')
        except KeyError:
            pass
        resp.headers['Content-Length'] = str(len(rewritten_body))
        resp._body = StringIO(rewritten_body)
        resp._already_read = False

dataset/ETHPy150Open benoitc/dj-revproxy/revproxy/filters.py RewriteBase.on_response/original