Exemplo n.º 1
0
    def test_modify_upload(self):
        """
        Upload parameter should be modified.
        """

        urls = (
            ("http://www.example.net/test?uploaded=123456",
             "http://www.example.net/test?uploaded=246912"),
            ("http://www.example.net/test?test1=val&test2=val&downloaded=5&uploaded=10",
             "http://www.example.net/test?test1=val&test2=val&downloaded=5&uploaded=20"),
            ("http://www.example.net:6969/test?uploaded=123456",
             "http://www.example.net:6969/test?uploaded=246912"),
            ("http://www.example.net:6969/test?test1=val&test2=val&downloaded=5&uploaded=10",
             "http://www.example.net:6969/test?test1=val&test2=val&downloaded=5&uploaded=20")
            )

        for pair in urls:
            self.assertEqual(cheatbt.cheat(pair[0], self.mappings), pair[1])
Exemplo n.º 2
0
    def test_normal(self):
        """
        These URLs should pass through without modification.
        """

        urls = (
            "http://www.example.net/",
            "http://www.example.net/?test",
            "http://www.example.net/test?test",
            "http://www.example.net/test?test=val",
            "http://www.example.net/test?uploaded=0",
            "http://www.example.net:6969/",
            "http://www.example.net:6969/?test",
            "http://www.example.net:6969/test?test",
            "http://www.example.net:6969/test?test=val",
            "http://www.example.net:6969/test?uploaded=0"
            )

        for url in urls:
            self.assertEqual(cheatbt.cheat(url, self.mappings), url)
Exemplo n.º 3
0
    def do_GET(self):
        """Called by BaseHTTPRequestHandler when a GET request is
        received from a client."""

        cheatpath = cheatbt.cheat(self.path, CheatHandler.mappings)

        logger = logging.getLogger("cheatproxy")
        logger.info(cheatpath)

        (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(cheatpath, "http")

        # TODO: https support.
        if scheme != "http" or fragment or not netloc:
            self.send_error(501)
            return

        soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        try:
            if self._connect_to(netloc, soc):
                request = urlparse.urlunparse(("", "", path, params, query, ""))
                soc.send("%s %s %s\r\n" % (self.command, request, self.request_version))
                self.headers["Connection"] = "close"
                del self.headers["Proxy-Connection"]
                # This is naughty. But rfc822.Message, which self.headers is a
                # subclass of, insists on converting headers to lowercase when
                # accessed conventionally (i.e. as a dict).
                for header in self.headers.headers:
                    header = header.strip() + "\r\n"
                    soc.send(header)
                    logger.debug(repr(header))
                soc.send("\r\n")
                self._read_write(soc)
        finally:
            soc.close()
            self.connection.close()