
    OJniQ                         d dl mZ d dlZddlmZ edz  Zeeef   dz  Z	 	 	 	 	 	 	 	 	 	 ddedededee	z  dz  d	ee
z  dz  d
ededededededeez  ez  fdZ	 	 	 	 	 ddededed
edededefdZy)    )AnyN   )utilsurl
proxy_addrheadersdata	json_datatimeoutredirect_urlreturn_cookiesinclude_cookiesverifyhttp2returnc                   K   |i }	 t        j                  |      }|s|rPt        j                  |||	|
      4 d{   }|j	                  | |||       d{   }ddd      d{    nNt        j                  |||	|
      4 d{   }|j                  | |d       d{   }ddd      d{    |rt        j                        S |r5t        j                  j                               }|r|j                  |fS |S j                  }	 |S 7 7 7 # 1 d{  7  sw Y   uxY w7 7 7 # 1 d{  7  sw Y   xY w# t        $ r}t        |      }Y d}~|S d}~ww xY ww)a  
    Sends an asynchronous HTTP request to the specified URL.

    This function supports both GET and POST requests. It allows for customization of headers,
    data, and other request parameters. It also handles proxy addresses, SSL verification,
    and HTTP/2 support.

    Args:
        url (str): The URL to send the request to.
        proxy_addr (OptionalStr): The proxy address to use. Defaults to None.
        headers (OptionalDict): Custom headers to include in the request. Defaults to None.
        data (dict | bytes | None): Data to send in the request body. Defaults to None.
        json_data (dict | list | None): JSON data to send in the request body. Defaults to None.
        timeout (int): The request timeout in seconds. Defaults to 20.
        redirect_url (bool): If True, returns the final URL after redirects. Defaults to False.
        return_cookies (bool): If True, returns the response cookies. Defaults to False.
        include_cookies (bool): If True, includes cookies in the response tuple. Defaults to False.
        verify (bool): If, True verifies the SSL certificate. Defaults to False.
        http2 (bool): If True, enables HTTP/2 support. Defaults to True.

    Returns:
        OptionalDict | OptionalStr | tuple: The response text, JSON data,
        or a tuple containing the response text and cookies.

    Raises:
        Exception: If an error occurs during the request.

    Example:
        >>> import asyncio
        >>> async def main():
        ...     result = await async_req("https://example.com", proxy_addr="http://proxy.example.com")
        ...     print(result)
        >>> asyncio.run(main())
        Response text or JSON data

    Note:
        - If `data` or `json_data` is provided, a POST request is sent; otherwise, a GET request is sent.
        - The `redirect_url` parameter only returns the final URL after following redirects.
        - If `return_cookies` is True, the function returns a tuple containing the response text and cookies.
    Nproxyr   r   r   )r	   jsonr   Tr   follow_redirects)r   handle_proxy_addrhttpxAsyncClientpostgetstrr   dictcookiesitemstext	Exception)r   r   r   r	   r
   r   r   r   r   r   r   clientresponsecookies_dictresp_stres                   N/home/uftp/myenv/lib/python3.12/site-packages/streamget/requests/async_http.py	async_reqr)      s    j ,,Z8
9((z7SYafg ^ ^kq!'St)U\!]]^ ^ ^ ((z7SYafg Y Ykq!'CSW!XXY Y x||$$ 0 0 6 6 89L4CHMM<0UU}}H O!^]^ ^ ^ ^YXY Y Y Y  q6Os   E46E DE D"DD" E +D ,"E D7E D=*D9+D=/E :D;;E E44E 
E4E E4E E4E D" E "D4(D+)D40E 9D=;E =EEEE 	E1E,&E4,E11E4c                 d  K   	 t        j                  |      }t        j                  ||||      4 d{   }|j	                  | |d       d{   }|j
                  cddd      d{    S 7 =7 #7 	# 1 d{  7  sw Y   yxY w# t        $ r}t        |       Y d}~yd}~ww xY ww)a  
    Checks if a URL returns a successful HTTP status code (200 OK).

    This function sends a HEAD request to the specified URL and checks the response status code.
    It supports custom headers, proxy addresses, and SSL verification.

    Args:
        url (str): The URL to check.
        proxy_addr (OptionalStr): The proxy address to use. Defaults to None.
        headers (OptionalDict): Custom headers to include in the request. Defaults to None.
        timeout (int): The request timeout in seconds. Defaults to 10.
        verify (bool): If True, verifies the SSL certificate. Defaults to False.
        http2 (bool): If True, enables HTTP/2 support. Defaults to True.

    Returns:
        int: such as 200, 304, 403.

    Raises:
        Exception: If an error occurs during the request.

    Example:
        >>> import asyncio
        >>> async def main():
        ...     status = await get_response_status("https://example.com")
        ...     print(status)
        >>> asyncio.run(main())
        200

    Note:
        - This function uses the HEAD request method, which is lightweight and suitable for checking status codes.
        - returns a status code other than 200 OK.
    r   NTr   F)r   r   r   r   headstatus_coder"   print)	r   r   r   r   r   r   r#   r$   r'   s	            r(   get_response_statusr.   X   s     P,,Z8
$$:wv]bc 	( 	(gm#[[gPT[UUH''	( 	( 	(U	( 	( 	( 	(
   as   B02B A4B A:A6A:"B .A8/B 3B04B 6A:8B :B BBB B0B 	B-B(#B0(B--B0)
NNNN   FFFFT)NN
   FT)typingr   r    r   r   OptionalStrr   OptionalDictbyteslistintbooltupler)   r.        r(   <module>r<      sD     DjCH~$
 #' $$((,"$ %JJJ J UlT!	J
 $;%J J J J J J J K%'J^ #' $/// / 	/
 / / 	/r;   