Constructs and sends a :py:class:`requests.Request`. Returns :py:class:`requests.Response` object. :param method: method for the new :class:`Request` object. :param url: URL for the new :class:`Request` object. :param name: (optional)
(self, method, url, name=None, **kwargs)
| 128 | self.data.req_resps.append(get_req_resp_record(resp_obj)) |
| 129 | |
| 130 | def request(self, method, url, name=None, **kwargs): |
| 131 | """ |
| 132 | Constructs and sends a :py:class:`requests.Request`. |
| 133 | Returns :py:class:`requests.Response` object. |
| 134 | |
| 135 | :param method: |
| 136 | method for the new :class:`Request` object. |
| 137 | :param url: |
| 138 | URL for the new :class:`Request` object. |
| 139 | :param name: (optional) |
| 140 | Placeholder, make compatible with Locust's HttpSession |
| 141 | :param params: (optional) |
| 142 | Dictionary or bytes to be sent in the query string for the :class:`Request`. |
| 143 | :param data: (optional) |
| 144 | Dictionary or bytes to send in the body of the :class:`Request`. |
| 145 | :param headers: (optional) |
| 146 | Dictionary of HTTP Headers to send with the :class:`Request`. |
| 147 | :param cookies: (optional) |
| 148 | Dict or CookieJar object to send with the :class:`Request`. |
| 149 | :param files: (optional) |
| 150 | Dictionary of ``'filename': file-like-objects`` for multipart encoding upload. |
| 151 | :param auth: (optional) |
| 152 | Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth. |
| 153 | :param timeout: (optional) |
| 154 | How long to wait for the server to send data before giving up, as a float, or \ |
| 155 | a (`connect timeout, read timeout <user/advanced.html#timeouts>`_) tuple. |
| 156 | :type timeout: float or tuple |
| 157 | :param allow_redirects: (optional) |
| 158 | Set to True by default. |
| 159 | :type allow_redirects: bool |
| 160 | :param proxies: (optional) |
| 161 | Dictionary mapping protocol to the URL of the proxy. |
| 162 | :param stream: (optional) |
| 163 | whether to immediately download the response content. Defaults to ``False``. |
| 164 | :param verify: (optional) |
| 165 | if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided. |
| 166 | :param cert: (optional) |
| 167 | if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. |
| 168 | """ |
| 169 | self.data = SessionData() |
| 170 | |
| 171 | # timeout default to 120 seconds |
| 172 | kwargs.setdefault("timeout", 120) |
| 173 | |
| 174 | # set stream to True, in order to get client/server IP/Port |
| 175 | kwargs["stream"] = True |
| 176 | |
| 177 | start_timestamp = time.time() |
| 178 | response = self._send_request_safe_mode(method, url, **kwargs) |
| 179 | response_time_ms = round((time.time() - start_timestamp) * 1000, 2) |
| 180 | |
| 181 | try: |
| 182 | client_ip, client_port = response.raw._connection.sock.getsockname() |
| 183 | self.data.address.client_ip = client_ip |
| 184 | self.data.address.client_port = client_port |
| 185 | logger.debug(f"client IP: {client_ip}, Port: {client_port}") |
| 186 | except Exception: |
| 187 | pass |
no test coverage detected