mikebridge commented on code in PR #45553:
URL: https://github.com/apache/superset/pull/45553#discussion_r4407242482


##########
superset/semantic_layers/transport.py:
##########
@@ -0,0 +1,421 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Host-owned provider HTTP policy with shared deadline enforcement."""
+
+from __future__ import annotations
+
+import heapq
+import logging
+import os
+import socket
+import threading
+import time
+from collections.abc import Callable, Mapping
+from contextvars import Token
+from dataclasses import dataclass, field
+from io import BytesIO
+from threading import Condition, Lock, Thread
+from typing import Any, TYPE_CHECKING
+from urllib.parse import SplitResult, urljoin, urlsplit
+
+import requests
+from flask import current_app, has_app_context
+from superset_core.semantic_layers.transport import (
+    ProviderRequestError,
+    ProviderRequestFailure as Failure,
+    ProviderResponse,
+    ProviderTransport,
+    RequestBudget,
+)
+from urllib3.exceptions import HTTPError
+
+from superset.utils.network import (
+    ConnectionDeadline,
+    NonPublicAddressError,
+    PinnedHTTPAdapter,
+    PROVIDER_DEADLINE,
+)
+
+if TYPE_CHECKING:
+    from requests.sessions import _Settings
+
+logger: logging.Logger = logging.getLogger(__name__)
+MAX_REDIRECTS: int = 3
+_CHUNK_BYTES: int = 65536
+
+
+class HostProviderTransport(ProviderTransport):
+    """Fix operator policy at construction; keep budgets and sockets 
call-local."""
+
+    def __init__(self, *, allow_internal_hosts: bool = False) -> None:
+        self._allow_internal: bool = allow_internal_hosts
+
+    def request(
+        self,
+        provider: str,
+        method: str,
+        url: str,
+        *,
+        budget: RequestBudget,
+        headers: Mapping[str, str] | None = None,
+        params: Mapping[str, Any] | None = None,
+        json: Any = None,
+        consume: Callable[[int], None] | None = None,
+    ) -> ProviderResponse:
+        # Do not coerce arbitrary objects while handling a URL-bearing failure.
+        provider = provider if isinstance(provider, str) else "Provider"
+        bound: _Deadline = _Deadline(budget.deadline)
+        token: Token[ConnectionDeadline | None] = PROVIDER_DEADLINE.set(bound)
+        try:
+            bound.remaining()  # No parsing, resolution or socket work after 
expiry.
+            self._validated_url(url)
+            with _DirectSession(allow_environment_ca=self._allow_internal) as 
session:
+                adapter: PinnedHTTPAdapter = PinnedHTTPAdapter(
+                    public_only=not self._allow_internal
+                )
+                session.mount("https://";, adapter)
+                session.mount("http://";, adapter)
+                hop: int
+                for hop in range(MAX_REDIRECTS + 1):
+                    with session.request(
+                        method,
+                        url,
+                        headers={**(headers or {}), "Accept-Encoding": 
"identity"},
+                        params=params,

Review Comment:
   Good catch. Added a loopback test in `6f48535cfc` that sends a real POST 
with `params={"page": "2"}` and `json={"query": "{ ok }"}`, and asserts that 
the server receives exactly that query string and decoded JSON body. Dropping 
either `params=` or `json=` from the `session.request` call still passes the 
existing transport tests but fails the new one.
   



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to