Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 5
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
Exemplo n.º 6
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