예제 #1
0
 def map_local_file(self, context, flow):
     host = flow.request.host
     if host in self.local_rule:
         rule, pathname = self.local_rule[host], flow.request.path.split(
             "?")[0]
         for match in rule:
             if match in pathname:
                 form = flow.request.urlencoded_form
                 local_file = rule[match] + pathname.replace(
                     '/', sep).replace(match, '', 1).lstrip(sep)
                 striped_file = re.sub(
                     r'[a-f0-9]{6}\.(js|css|jpg|png|jpeg|gif)$', r'.\1',
                     local_file)
                 if path.isfile(local_file) or path.isfile(striped_file):
                     if path.exists(striped_file): local_file = striped_file
                     content_type = mimetypes.guess_type(local_file)[0]
                     if content_type[0] is None: break
                     body = str(open(local_file).read())
                     h = self.custom_header(host, content_type,
                                            str(len(body)))
                     response = HTTPResponse(http_version=b"HTTP/1.1",
                                             status_code=200,
                                             reason="local",
                                             headers=h,
                                             content=body)
                     response.is_replay = True
                     flow.response = response
                     context.log(
                         "\n%s\n%s\nReplied with Local File:\n%s\n%s\n%s\n"
                         % (flow.request.path, '-' * 60, '-' * 80,
                            local_file, "-" * 80))
                     break
     else:
         if flow.live and DEFAULT_PROXY is not None:
             self.proxy_request_to_upstream(context, flow, DEFAULT_PROXY)
예제 #2
0
 def response_config_rule(self, context, flow):
     host, path = flow.request.host, flow.request.path
     h = self.custom_header(host, 'text/plain', '7')
     h['location'] = 'http://' + host + path
     response = HTTPResponse(http_version=b"HTTP/1.1",
                             status_code=200,
                             reason='ok',
                             headers=h,
                             content='{ret:0}')
     response.is_replay = True
     flow.reply(response)
예제 #3
0
 def redirect_https_to_http(self, context, flow):
     host, path = flow.request.host, flow.request.path
     h = self.custom_header(host, None, '0')
     h['location'] = 'http://' + host + path
     response = HTTPResponse(http_version=b"HTTP/1.1",
                             status_code=302,
                             reason='redirect',
                             headers=h,
                             content='')
     response.is_replay = True
     flow.reply(response)