Exemplo n.º 1
0
 def do_GET(self):
     if not self._try_handler("GET"):
         res = self._find_path()
         if res:
             self.path, self.disk_root = res
             # don't include query string and fragment, and prepend
             # host directory if required.
             if self.request.netloc and self.proxy_host_dirs:
                 self.path = "/" + self.request.netloc + self.path
             SimpleHTTPRequestHandler.do_GET(self)
         else:
             self.send_response(404)
             self.end_headers()
             self.wfile.write(b"")
Exemplo n.º 2
0
    def do_GET(self, *args, **kwargs):

        # 1. Redirect all requests to `/MAGIC_REDIRECT/`.
        if self.path.startswith('/MAGIC_REDIRECT/'):
            parsed_path = urlparse(self.path)
            qs = parse_qs(parsed_path.query)
            if 'dst' not in qs:
                self.send_error(
                    404,
                    "Requests to the path `/MAGIC_REDIRECT/` must specify "
                    "a destination to redirect to via a `dst` query parameter."
                )
                return
            dst = qs['dst'][0]
            new_qs = list()
            if len(qs['dst']) > 1:
                new_qs.append('dst=' + '&dst='.join(qs['dst'][1:]))
            for key in qs.keys():
                if key == 'dst':
                    continue
                temp = '%s=' + '&%s='.join(qs[key])
                new_qs.append(temp % key)
            if len(new_qs) > 0:
                new_url = "%s?%s" % (dst, '&'.join(new_qs))
            else:
                new_url = dst
            self.send_response(301)
            self.send_header("Location", new_url)
            self.end_headers()
            return

        # Otherwise, return file from disk
        return SimpleHTTPRequestHandler.do_GET(self, *args, **kwargs)
Exemplo n.º 3
0
 def serve_file(self):
     """
     If a file exists corresponding to the request's path, serve it.
     Otherwise, raise IOError.
     """
     path = self.translate_path(self.path)
     try:
         open(path, 'rb')
     except IOError:
         raise
     else:
         return SimpleHTTPRequestHandler.do_GET(self)
Exemplo n.º 4
0
 def serve_file(self):
     """
     If a file exists corresponding to the request's path, serve it.
     Otherwise, raise IOError.
     """
     path = self.translate_path(self.path)
     try:
         open(path, 'rb')
     except IOError:
         raise
     else:
         return SimpleHTTPRequestHandler.do_GET(self)
Exemplo n.º 5
0
    def do_GET(self):  # pylint: disable=invalid-name
        """
        Check parameters to see if a delay was specified.
        If so then wait and then serve the GET request.
        """
        # Parse the url into components
        parsed_url = urlparse(self.path)

        # Determine if delay was passed as a parameter
        delay_time = parse_qs(parsed_url.query).get('delay')

        if delay_time:
            # Values are passed as a list of strings
            # so keep the first value and convert to a float.
            sleep(float(delay_time[0]))

        # Prepend "tests/site" to the path because that
        # is where the test files should be served from.
        self.path = "tests/site{}".format(self.path)

        return SimpleHTTPRequestHandler.do_GET(self)