Ejemplo n.º 1
0
    def __init__(self,
                 host,
                 port=None,
                 key_file=None,
                 cert_file=None,
                 strict=None,
                 timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
                 ssl_context=None,
                 server_hostname=None,
                 **kw):

        HTTPConnection.__init__(self,
                                host,
                                port,
                                strict=strict,
                                timeout=timeout,
                                **kw)

        self.key_file = key_file
        self.cert_file = cert_file
        self.ssl_context = ssl_context
        self.server_hostname = server_hostname

        # Required property for Google AppEngine 1.9.0 which otherwise causes
        # HTTPS requests to go out as HTTP. (See Issue #356)
        self._protocol = 'https'
Ejemplo n.º 2
0
 def __init__(self, *args, **kwargs):
     HTTPConnection.__init__(self, *args, **kwargs)
     self._original_response_cls = self.response_class
     # We'd ideally hook into httplib's states, but they're all
     # __mangled_vars so we use our own state var.  This variable is set
     # when we receive an early response from the server.  If this value is
     # set to True, any calls to send() are noops.  This value is reset to
     # false every time _send_request is called.  This is to workaround the
     # fact that py2.6 (and only py2.6) has a separate send() call for the
     # body in _send_request, as opposed to endheaders(), which is where the
     # body is sent in all versions > 2.6.
     self._response_received = False
     self._expect_header_set = False
Ejemplo n.º 3
0
 def test_connection_source_address(self):
     try:
         # source_address does not exist in Py26-
         HTTPConnection('localhost', 12345, source_address='127.0.0.1')
     except TypeError as e:
         pytest.fail(
             'HTTPConnection raised TypeError on source_adddress: %r' % e)
Ejemplo n.º 4
0
    def _tunnel(self):
        # Works around a bug in py26 which is fixed in later versions of
        # python. Bug involves hitting an infinite loop if readline() returns
        # nothing as opposed to just ``\r\n``.
        # As much as I don't like having if py2: <foo> code blocks, this seems
        # the cleanest way to handle this workaround.  Fortunately, the
        # difference from py26 to py3 is very minimal.  We're essentially
        # just overriding the while loop.
        if sys.version_info[:2] != (2, 6):
            return HTTPConnection._tunnel(self)

        # Otherwise we workaround the issue.
        self._set_hostport(self._tunnel_host, self._tunnel_port)
        self.send("CONNECT %s:%d HTTP/1.0\r\n" % (self.host, self.port))
        for header, value in self._tunnel_headers.iteritems():
            self.send("%s: %s\r\n" % (header, value))
        self.send("\r\n")
        response = self.response_class(self.sock,
                                       strict=self.strict,
                                       method=self._method)
        (version, code, message) = response._read_status()

        if code != 200:
            self.close()
            raise socket.error("Tunnel connection failed: %d %s" %
                               (code, message.strip()))
        while True:
            line = response.fp.readline()
            if not line:
                break
            if line in (b'\r\n', b'\n', b''):
                break
Ejemplo n.º 5
0
 def test_connection_source_address(self):
     try:
         # source_address does not exist in Py26-
         HTTPConnection("localhost", 12345, source_address="127.0.0.1")
     except TypeError as e:
         pytest.fail(
             "HTTPConnection raised TypeError on source_address: %r" % e)
Ejemplo n.º 6
0
    def test_connection_strict(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            # strict=True is deprecated in Py33+
            conn = HTTPConnection('localhost', 12345, strict=True)

            if w:
                self.fail('HTTPConnection raised warning on strict=True: %r' % w[0].message)
Ejemplo n.º 7
0
def postRequest(threadNum):

    #定义需要进行发送的数据

    #接口
    # requrl ="http://192.168.1.249:9901/hkjf/login.do?method=indexlogin"
    requrl = "http://192.168.1.249:9901/hkjf/login.do?method=indexlogin"
    #请求服务,例如:www.baidu.com
    hostServer = "192.168.1.249"
    #连接服务器
    conn = HTTPConnection(hostServer)
    #发送请求
    # conn.request(method="POST",url=requrl,body=postData)
    content = {
        'login': tel,
        'password':
        '******',
        'pwdLevel': '2',
        'verify_code': '请输入计算结果',
        'randCode': '请输入您的6位验证码',
        'commendPhone': '请输入推荐码(推荐人手机号后8位)',
        'loginregister': '请输入您的手机号',
        'passwordresgister': '',
        'token': '',
        'modulus': '',
        'exponent': '',
        'newToken': '',
        'phoneId': '',
        'code': '',
        'utype': '',
        'csrftoken': '',
        'pwdLevel': ''
    }
    response = requests.post(
        'http://192.168.1.249:9901/hkjf/login.do?method=indexlogin',
        data=content)
    #获取请求响应

    #打印请求状态
    if response.status_code in range(200, 300):
        print(u"线程" + str(threadNum) + u"状态码:" + str(response.status_code))
    conn.close()
Ejemplo n.º 8
0
 def _send_request(self, method, url, body, headers, *args, **kwargs):
     self._response_received = False
     if headers.get('Expect', b'') == b'100-continue':
         self._expect_header_set = True
     else:
         self._expect_header_set = False
         self.response_class = self._original_response_cls
     rval = HTTPConnection._send_request(self, method, url, body, headers,
                                         *args, **kwargs)
     self._expect_header_set = False
     return rval
Ejemplo n.º 9
0
 def getresponse(self, *args, **kwargs):
     ret = HTTPConnection.getresponse(self, *args, **kwargs)
     self._last_rtt = time.time() - self._request_start
     return ret
Ejemplo n.º 10
0
 def request(self, *args, **kwargs):
     self._request_start = time.time()
     return HTTPConnection.request(self, *args, **kwargs)
Ejemplo n.º 11
0
 def connect(self):
     self._connected_since = time.time()
     return HTTPConnection.connect(self)
Ejemplo n.º 12
0
 def send(self, str):
     if self._response_received:
         return
     return HTTPConnection.send(self, str)