
xao                 @   s<   d  d l  Z  d  d l m Z m Z d  d l Td d   Z d S)    N)ResponseRequest)*c             C   s(   |  j  d d  }  |  j  d d  }  |  S)uC  
    Allow you do some custom modifications/rewrites to the response content.
        eg: add your own statistic code
    Only text content (txt/html/css/js/json) would be passed to this function

    Notice: the remote response "Location" headers(occurs in 301/302/307) will be passed to this function too,
        with an special content_mime as "mwm/headers-location"

    Please remember to set `custom_text_rewriter_enable` to True in the config

    (请先看完上面的英文)
    在简单情况下, 你可以只对源站的响应文本进行一些简单的字符串上的修改(比如添加你自己的统计代码, 改一些文字之类)

    稍微复杂一点, 你还可以调用zmirror本身的其他实用函数,
      以内置twitter镜像为例, 它调用了zmirror内置的 encode_mirror_url() 函数, 来将url转化为镜像url

    更加高级一点, 在自定义重写函数中, 还能影响zmirror本身的行为,
      比如可以通过 try_match_and_add_domain_to_rewrite_white_list() 动态添加域名到重写名单(external_domains)中,

    :param raw_text: raw response html/css/js text content
    :type raw_text: str
    :param content_mime: response's mime
    :type content_mime: str
    :param remote_url: remote url
    :type remote_url: str
    :return: modified response text content
    :rtype: str
    zwww.googletagmanager.com z%www.google-analytics.com/analytics.js)replace)raw_textZcontent_mime
remote_url r	   /var/www/zmirror/custom_func.pycustom_response_text_rewriter   s    "r   )reflaskr   r   zmirror.zmirrorr   r	   r	   r	   r
   <module>   s   
