code: def _on_connect(self, stream):
      if self.final_callback is None:
          # final_callback is cleared if we've hit our timeout.
          stream.close()
          return
      self.stream = stream
      self.stream.set_close_callback(self.on_connection_close)
      self._remove_timeout()
      if self.final_callback is None:
          return
      if self.request.request_timeout:
          self._timeout = self.io_loop.add_timeout(
              self.start_time + self.request.request_timeout,
              stack_context.wrap(
                  functools.partial(self._on_timeout, "during request")
              ),
          )
      if (
          self.request.method not in self._SUPPORTED_METHODS
          and not self.request.allow_nonstandard_methods
      ):
          raise KeyError("unknown method %s" % self.request.method)
      for key in (
          "network_interface",
          "proxy_host",
          "proxy_port",
          "proxy_username",
          "proxy_password",
          "proxy_auth_mode",
      ):
          if getattr(self.request, key, None):
              raise NotImplementedError("%s not supported" % key)
      if "Connection" not in self.request.headers:
          self.request.headers["Connection"] = "close"
      if "Host" not in self.request.headers:
          if "@" in self.parsed.netloc:
              self.request.headers[
                  "Host"
              ] = self.parsed.netloc.rpartition("@")[-1]
          else:
              self.request.headers["Host"] = self.parsed.netloc
      username, password = None, None
      if self.parsed.username is not None:
          username, password = (
              self.parsed.username,
              self.parsed.password,
          )
      elif self.request.auth_username is not None:
          username = self.request.auth_username
          password = self.request.auth_password or ""
      if username is not None:
          if self.request.auth_mode not in (None, "basic"):
              raise ValueError(
                  "unsupported auth_mode %s", self.request.auth_mode
              )
          auth = utf8(username) + b":" + utf8(password)
          self.request.headers[
              "Authorization"
          ] = b"Basic " + base64.b64encode(auth)
      if self.request.user_agent:
          self.request.headers["User-Agent"] = self.request.user_agent
      if not self.request.allow_nonstandard_methods:
          # Some HTTP methods nearly always have bodies while others
          # almost never do. Fail in this case unless the user has
          # opted out of sanity checks with allow_nonstandard_methods.
          body_expected = self.request.method in (
              "POST",
              "PATCH",
              "PUT",
          )
          body_present = (
              self.request.body is not None
              or self.request.body_producer is not None
          )
          if (body_expected and not body_present) or (
              body_present and not body_expected
          ):
              raise ValueError(
                  "Body must %sbe None for method %s (unless "
                  "allow_nonstandard_methods is true)"
                  % (
                      "not " if body_expected else "",
                      self.request.method,
                  )
              )
      if self.request.expect_100_continue:
          self.request.headers["Expect"] = "100-continue"
      if self.request.body is not None:
          # When body_producer is used the caller is responsible for
          # setting Content-Length (or else chunked encoding will be used).
          self.request.headers["Content-Length"] = str(
              len(self.request.body)
          )
      if (
          self.request.method == "POST"
          and "Content-Type" not in self.request.headers
      ):
          self.request.headers[
              "Content-Type"
          ] = "application/x-www-form-urlencoded"
      if self.request.decompress_response:
          self.request.headers["Accept-Encoding"] = "gzip"
      req_path = (self.parsed.path or "/") + (
          ("?" + self.parsed.query) if self.parsed.query else ""
      )
      self.connection = self._create_connection(stream)
      start_line = httputil.RequestStartLine(
          self.request.method, req_path, ""
      )
      self.connection.write_headers(start_line, self.request.headers)
      if self.request.expect_100_continue:
          self._read_response()
      else:
          self._write_body(True)
  
imports: from __future__ import absolute_import, division, print_function
  from tornado.escape import utf8, _unicode
  from tornado import gen
  from tornado.httpclient import HTTPResponse, HTTPError, AsyncHTTPClient, main, _RequestProxy
  from tornado import httputil
  from tornado.http1connection import HTTP1Connection, HTTP1ConnectionParameters
  from tornado.iostream import StreamClosedError
  from tornado.netutil import Resolver, OverrideResolver, _client_ssl_defaults
  from tornado.log import gen_log
  from tornado import stack_context
  from tornado.tcpclient import TCPClient
  from tornado.util import PY3
  import base64
  import collections
  import copy
  import functools
  import re
  import socket
  import sys
  from io import BytesIO
label_desc: Use image node_id 5 for calling the _HTTPConnection obj's underlying member method code with example usage: obj._on_connect(stream) without return types