code: def read_http_stream(
      url: str,
      *,
      lines: bool = False,
      decode_unicode: bool = False,
      chunk_size: int = 1024,
      auth: Optional[tuple[str, str]] = None,
  ) -> Iterable[str] | Iterable[bytes]:
      """
      Read data from ``url`` in a stream, either all at once or line-by-line.
  
      Args:
          url: URL to which a GET request is made for data.
          lines: If False, yield all of the data at once; otherwise, yield data line-by-line.
          decode_unicode: If True, yield data as unicode, where the encoding
              is taken from the HTTP response headers; otherwise, yield bytes.
          chunk_size: Number of bytes read into memory per chunk.
              Because decoding may occur, this is not necessarily the length of each chunk.
          auth: (username, password) pair for simple HTTP authentication required (if at all)
              to access the data at ``url``.
  
              .. seealso:: http://docs.python-requests.org/en/master/user/authentication/
  
      Yields:
          If ``lines`` is True, the next line in the response data,
          which is bytes if ``decode_unicode`` is False or unicode otherwise.
          If ``lines`` is False, yields the full response content, either as bytes
          or unicode.
      """
      # always close the connection
      with closing(requests.get(url, stream=True, auth=auth)) as r:
          # set fallback encoding if unable to infer from headers
          if r.encoding is None:
              r.encoding = "utf-8"
          if lines is False:
              if decode_unicode is True:
                  yield r.text
              else:
                  yield r.content
          else:
              lines_ = r.iter_lines(
                  chunk_size=chunk_size, decode_unicode=decode_unicode
              )
              for line in lines_:
                  if line:
                      yield line
  
file_path: textacy/src/textacy/io/http.py
imports: from __future__ import annotations
  import logging
  from contextlib import closing
  from typing import Iterable, Optional
  import requests
  from tqdm import tqdm
  from ..None import types, utils
  from .None import utils
label_desc: Use image node_id 1 for calling a global function with example usage: read_http_stream(url) without return types