Lee-W commented on code in PR #44302:
URL: https://github.com/apache/airflow/pull/44302#discussion_r1860245080


##########
providers/src/airflow/providers/http/hooks/http.py:
##########
@@ -102,49 +120,68 @@ def get_conn(self, headers: dict[Any, Any] | None = None) 
-> requests.Session:
         """
         Create a Requests HTTP session.
 
-        :param headers: additional headers to be passed through as a dictionary
+        :param headers: Additional headers to be passed through as a 
dictionary.
+        :return: A configured requests.Session object.
         """
         session = requests.Session()
+        connection = self.get_connection(self.http_conn_id)
 
-        if self.http_conn_id:
-            conn = self.get_connection(self.http_conn_id)
+        self._set_base_url(connection)
+        self._set_auth(session, connection)
+        self._set_extra(session, connection)
+        self._mount_adapters(session)
 
-            if conn.host and "://" in conn.host:
-                self.base_url = conn.host
-            else:
-                # schema defaults to HTTP
-                schema = conn.schema if conn.schema else "http"
-                host = conn.host if conn.host else ""
-                self.base_url = f"{schema}://{host}"
-
-            if conn.port:
-                self.base_url += f":{conn.port}"
-            if conn.login:
-                session.auth = self.auth_type(conn.login, conn.password)
-            elif self._auth_type:
-                session.auth = self.auth_type()
-            if conn.extra:
-                extra = conn.extra_dejson
-                extra.pop(
-                    "timeout", None
-                )  # ignore this as timeout is only accepted in request method 
of Session
-                extra.pop("allow_redirects", None)  # ignore this as only 
max_redirects is accepted in Session
-                session.proxies = extra.pop("proxies", extra.pop("proxy", {}))
-                session.stream = extra.pop("stream", False)
-                session.verify = extra.pop("verify", extra.pop("verify_ssl", 
True))
-                session.cert = extra.pop("cert", None)
-                session.max_redirects = extra.pop("max_redirects", 
DEFAULT_REDIRECT_LIMIT)
-                session.trust_env = extra.pop("trust_env", True)
-
-                try:
-                    session.headers.update(extra)
-                except TypeError:
-                    self.log.warning("Connection to %s has invalid extra 
field.", conn.host)
         if headers:
             session.headers.update(headers)
 
         return session
 
+    def _set_base_url(self, connection) -> None:
+        host = connection.host or ""
+        schema = connection.schema or "http"
+        if "://" in host:
+            self.base_url = host
+        else:
+            self.base_url = f"{schema}://{host}" if host else f"{schema}://"
+            if connection.port:
+                self.base_url += f":{connection.port}"

Review Comment:
   got it. sounds good! Thanks for the explanation!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to