Esempio n. 1
0
 def test_pac_file_served_from_buffer(
         self, mock_fromfd: mock.Mock, mock_selector: mock.Mock) -> None:
     self._conn = mock_fromfd.return_value
     self.mock_selector_for_client_read(mock_selector)
     pac_file_content = b'function FindProxyForURL(url, host) { return "PROXY localhost:8899; DIRECT"; }'
     self.init_and_make_pac_file_request(text_(pac_file_content))
     self.protocol_handler.run_once()
     self.assertEqual(
         self.protocol_handler.request.state,
         httpParserStates.COMPLETE)
     self._conn.send.called_once_with(build_http_response(
         200, reason=b'OK', headers={
             b'Content-Type': b'application/x-ns-proxy-autoconfig',
             b'Connection': b'close'
         }, body=pac_file_content
     ))
Esempio n. 2
0
 def handle_client_request(self,
                           request: HttpParser) -> Optional[HttpParser]:
     if request.method == httpMethods.GET:
         path_str = text_(request.path)
         downloaded = 0
         match = re.search('(?:^|\\?|&)downloaded=(\\d+)(?:&|$)', path_str)
         if match:
             downloaded = int(match.group(1))
         match = re.search('(?:^|\\?|&)uploaded=(\\d+)(?:&|$)', path_str)
         if match:
             uploaded = int(downloaded *
                            1.2 if downloaded > 0 else int(match.group(1)) *
                            1.2)
             path_str = path_str[:match.start(1)] + str(
                 uploaded) + path_str[match.end(1):]
             request.path = bytes_(path_str)
     return request
Esempio n. 3
0
 def test_text_int(self) -> None:
     self.assertEqual(text_(1), '1')
Esempio n. 4
0
 def test_text_nochange(self) -> None:
     self.assertEqual(text_('hello'), 'hello')
Esempio n. 5
0
 def test_text(self) -> None:
     self.assertEqual(text_(b'hello'), 'hello')