Esempio n. 1
0
 def __init__(self, request, client_address, server, app_object):
     # type: (bytes, Tuple[str, int], HTTPServer, Chalice) -> None
     self.app_object = app_object
     self.event_converter = LambdaEventConverter(
         RouteMatcher(list(app_object.routes)))
     BaseHTTPRequestHandler.__init__(
         self, request, client_address, server)  # type: ignore
Esempio n. 2
0
    def send_response(self, status_code, content=None, headers=None):
        """
        Send a response back to the client with the HTTP `status_code` (int),
        `content` (str) and `headers` (dict).
        """
        self.log_message(
            "Sent HTTP response: {0} with content '{1}' and headers {2}".
            format(status_code, content, headers))

        if headers is None:
            headers = {
                'Access-Control-Allow-Origin': "*",
            }

        BaseHTTPRequestHandler.send_response(self, status_code)

        for (key, value) in headers.items():
            self.send_header(key, value)

        if len(headers) > 0:
            self.end_headers()

        if content is not None:
            if not six.PY2 and isinstance(content, six.text_type):
                content = content.encode('utf-8')
            self.wfile.write(content)
Esempio n. 3
0
 def __init__(self, request, client_address, server):
     self.request = request
     self.client_address = client_address
     self.server = server
     self.proxy = server.my_object
     self.data_bytes = None
     BaseHTTPRequestHandler.__init__(self, request, client_address, server)
Esempio n. 4
0
 def __init__(self, request, client_address, server):
     self.request = request
     self.client_address = client_address
     self.server = server
     self.proxy = server.my_object
     self.data_bytes = None
     self.protocol_version = self.proxy.protocol_version
     BaseHTTPRequestHandler.__init__(self, request, client_address, server)
Esempio n. 5
0
 def __init__(self, *args, **kwargs):
     from google.appengine._internal.django.conf import settings
     self.admin_media_prefix = settings.ADMIN_MEDIA_PREFIX
     # We set self.path to avoid crashes in log_message() on unsupported
     # requests (like "OPTIONS").
     self.path = ''
     self.style = color_style()
     BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
Esempio n. 6
0
 def __init__(self, request, client_address, server, app_object):
     # type: (bytes, Tuple[str, int], HTTPServer, Chalice) -> None
     self.app_object = app_object
     self.event_converter = LambdaEventConverter(
         RouteMatcher(list(app_object.routes)),
         self.app_object.api.binary_types
     )
     BaseHTTPRequestHandler.__init__(
         self, request, client_address, server)  # type: ignore
Esempio n. 7
0
 def __init__(self, request, client_address, server, app_object):
     # type: (bytes, Tuple[str, int], HTTPServer, Chalice) -> None
     self.app_object = app_object
     self.event_converter = LambdaEventConverter(
         RouteMatcher(list(app_object.routes)),
         self.app_object.api.binary_types)
     BaseHTTPRequestHandler.__init__(self, request, client_address,
                                     server)  # type: ignore
     # Force BaseHTTPRequestHandler to use HTTP/1.1
     # Chrome ignores many headers from HTTP/1.0 servers.
     BaseHTTPRequestHandler.protocol_version = "HTTP/1.1"
Esempio n. 8
0
 def __init__(self, request, client_address, server):
     self.request = request
     self.client_address = client_address
     self.server = server
     self.proxy = server.my_object
     self.data_bytes = None
     self.protocol_version = self.proxy.protocol_version
     try:
         BaseHTTPRequestHandler.__init__(self, request, client_address, server)
     except SSLError as e:
         LOG.warning('SSL error when handling request: %s' % e)
Esempio n. 9
0
 def __init__(self, request, client_address, server):
     self.request = request
     self.client_address = client_address
     self.server = server
     self.proxy = server.my_object
     self.data_bytes = None
     self.protocol_version = self.proxy.protocol_version
     try:
         BaseHTTPRequestHandler.__init__(self, request, client_address, server)
     except SSLError as e:
         LOG.warning('SSL error when handling request: %s' % e)
     except Exception as e:
         if 'cannot read from timed out object' not in str(e):
             LOG.warning('Unknown error: %s' % e)
Esempio n. 10
0
 def parse_request(self):
     """Contain a hook to simulate closed connection."""
     # Parse the request first
     # BaseHTTPRequestHandler is old style class in 2.7
     if type(FetcherTestHandler) == type:
         result = super(FetcherTestHandler, self).parse_request()
     else:
         result = BaseHTTPRequestHandler.parse_request(self)
     # If the connection should be closed, do so.
     if self.path == '/closed':
         self.wfile.close()
         return False
     else:
         # Otherwise continue as usual.
         return result
Esempio n. 11
0
 def parse_request(self):
     """Contain a hook to simulate closed connection."""
     # Parse the request first
     # BaseHTTPRequestHandler is old style class in 2.7
     if type(FetcherTestHandler) == type:
         result = super(FetcherTestHandler, self).parse_request()
     else:
         result = BaseHTTPRequestHandler.parse_request(self)
     # If the connection should be closed, do so.
     if self.path == '/closed':
         self.wfile.close()
         return False
     else:
         # Otherwise continue as usual.
         return result
Esempio n. 12
0
 def parse_request(self):
     result = BaseHTTPRequestHandler.parse_request(self)
     if not result:
         return result
     if sys.version_info[0] >= 3:
         return result
     # Required fix for Python 2 (otherwise S3 uploads are hanging), based on the Python 3 code:
     # https://sourcecodebrowser.com/python3.2/3.2.3/http_2server_8py_source.html#l00332
     expect = self.headers.get('Expect', '')
     if (expect.lower() == '100-continue' and
             self.protocol_version >= 'HTTP/1.1' and
             self.request_version >= 'HTTP/1.1'):
         if self.request_version != 'HTTP/0.9':
             self.wfile.write(('%s %d %s\r\n' %
                 (self.protocol_version, 100, 'Continue')).encode('latin1', 'strict'))
             self.end_headers()
     return result
Esempio n. 13
0
    def parse_request(self):
        """Override parse_request method to enrich basic functionality of `BaseHTTPRequestHandler` class

        Original class can only invoke do_GET, do_POST, do_PUT, etc method implementations if they are defined.
        But we would like to have at least some simple routing mechanism, i.e.:
        GET /uri1/part2 request should invoke `do_GET_uri1()`
        POST /other should invoke `do_POST_other()`

        If the `do_<REQUEST_METHOD>_<first_part_url>` method does not exists we'll fallback to original behavior."""

        ret = BaseHTTPRequestHandler.parse_request(self)
        if ret:
            mname = self.path.lstrip('/').split('/')[0]
            mname = self.command + ('_' + mname if mname else '')
            if hasattr(self, 'do_' + mname):
                self.command = mname
        return ret
 def parse_request(self):
     result = BaseHTTPRequestHandler.parse_request(self)
     if not result:
         return result
     if sys.version_info[0] >= 3:
         return result
     # Required fix for Python 2 (otherwise S3 uploads are hanging), based on the Python 3 code:
     # https://sourcecodebrowser.com/python3.2/3.2.3/http_2server_8py_source.html#l00332
     expect = self.headers.get('Expect', '')
     if (expect.lower() == '100-continue' and
             self.protocol_version >= 'HTTP/1.1' and
             self.request_version >= 'HTTP/1.1'):
         if self.request_version != 'HTTP/0.9':
             self.wfile.write(('%s %d %s\r\n' %
                 (self.protocol_version, 100, 'Continue')).encode('latin1', 'strict'))
             self.end_headers()
     return result
Esempio n. 15
0
    def parse_request(self):
        """Override parse_request method to enrich basic functionality of `BaseHTTPRequestHandler` class

        Original class can only invoke do_GET, do_POST, do_PUT, etc method implementations if they are defined.
        But we would like to have at least some simple routing mechanism, i.e.:
        GET /uri1/part2 request should invoke `do_GET_uri1()`
        POST /other should invoke `do_POST_other()`

        If the `do_<REQUEST_METHOD>_<first_part_url>` method does not exists we'll fallback to original behavior."""

        ret = BaseHTTPRequestHandler.parse_request(self)
        if ret:
            mname = self.path.lstrip('/').split('/')[0]
            mname = self.command + ('_' + mname if mname else '')
            if hasattr(self, 'do_' + mname):
                self.command = mname
        return ret
 def handle_one_request(self):
     try:
         BaseHTTPRequestHandler.handle_one_request(self)
     except socket.error:
         pass
Esempio n. 17
0
 def __init__(self, request, client_address, server):
     self.auth = b'Basic ' + base64.encodestring(b'test:test')[:-1]
     self.count = 0
     BaseHTTPRequestHandler.__init__(self, request, client_address, server)
Esempio n. 18
0
   def __init__(self, *args, **param):
       """
 """
       BaseHTTPRequestHandler.__init__(self, *args, **param)
Esempio n. 19
0
 def __init__(self, request, client_address, server, app_object, config):
     # type: (bytes, Tuple[str, int], HTTPServer, Chalice, Config) -> None
     self.local_gateway = LocalGateway(app_object, config)
     BaseHTTPRequestHandler.__init__(self, request, client_address,
                                     server)  # type: ignore
Esempio n. 20
0
 def end_headers(self):
     self.send_header("X-Clacks-Overhead", "GNU Terry Pratchett")
     BaseHTTPRequestHandler.end_headers(self)
Esempio n. 21
0
 def __init__(self, request, client_address, server):
     try:
         BaseHTTPRequestHandler.__init__(self, request, client_address,
                                         server)
     except (IOError, OSError) as e:
         pass
Esempio n. 22
0
 def __init__(self, request, client_address, server):
     self.__router = Router(self, server.routes)
     BaseHTTPRequestHandler.__init__(self, request, client_address, server)
Esempio n. 23
0
 def finish(self):
     return BaseHTTPRequestHandler.finish(self)
Esempio n. 24
0
 def __init__(self, request, client_address, server, listen_path, state=None):
     """Overriding default init to add listen_path and state"""
     self.listen_path = listen_path
     self.state = state
     self.keep_listening = True    # This will be set to false once we have a code
     BaseHTTPRequestHandler.__init__(self, request, client_address, server)
 def __init__(self, request, client_address, server):
     BaseHTTPRequestHandler.__init__(self, request, client_address, server)
Esempio n. 26
0
 def __init__(self, *args, **kwargs):
     self.user = None
     BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
Esempio n. 27
0
 def __init__(self, request, client_address, video_server):
     self._logger = logging.getLogger(self.__class__.__name__)
     self.event = None
     self.video_server = video_server
     BaseHTTPRequestHandler.__init__(self, request, client_address, video_server)
 def __init__(self, settings, *args, **kwargs):
     self.settings = settings
     self.server_list = []
     self.client_details = self.settings.companion_receiver()
     BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
Esempio n. 29
0
 def __init__(self, request, client_address, server, app_object, config):
     # type: (bytes, Tuple[str, int], HTTPServer, Chalice, Config) -> None
     self.local_gateway = LocalGateway(app_object, config)
     BaseHTTPRequestHandler.__init__(
         self, request, client_address, server)  # type: ignore
Esempio n. 30
0
 def __init__(self, request, client_address, server):
     self.auth = b'Basic ' + base64.encodestring(b'test:test')[:-1]
     self.count = 0
     BaseHTTPRequestHandler.__init__(self, request, client_address, server)
Esempio n. 31
0
 def version_string(self):
     return BaseHTTPRequestHandler.version_string(self).strip()
Esempio n. 32
0
 def handle(self):
     return BaseHTTPRequestHandler.handle(self)
Esempio n. 33
0
 def handle_one_request(self):
     try:
         BaseHTTPRequestHandler.handle_one_request(self)
     except socket.error:
         pass
Esempio n. 34
0
 def setup(self):
     # If the client is unreachable for 5 seconds, close the connection
     self.timeout = 5
     BaseHTTPRequestHandler.setup(self)
Esempio n. 35
0
 def setup(self):
     # If the client is unreachable for 5 seconds, close the connection
     self.timeout = 5
     BaseHTTPRequestHandler.setup(self)
Esempio n. 36
0
 def setup(self):
     BaseHTTPRequestHandler.setup(self)
     self.request.settimeout(5)
Esempio n. 37
0
 def handle_one_request(self):
     self.__start_time = time.time()
     BaseHTTPRequestHandler.handle_one_request(self)
Esempio n. 38
0
 def handle(self):
     # don't bother logging disconnects while handling a request
     try:
         BaseHTTPRequestHandler.handle(self)
     except SocketErrors as exce:
         self.wsgi_connection_drop(exce)
Esempio n. 39
0
 def __init__(self, *args, **kwargs):
     self.user = None
     BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
Esempio n. 40
0
 def __init__(self, request, client_address, server):
     BaseHTTPRequestHandler.__init__(self, request, client_address,
                                     server)
Esempio n. 41
0
 def __init__(self, request, client_address, video_server):
     self._logger = logging.getLogger(self.__class__.__name__)
     self.event = None
     self.video_server = video_server
     BaseHTTPRequestHandler.__init__(self, request, client_address,
                                     video_server)