@@ -116,15 +116,38 @@ def sdk_init(
116
116
) -> Tuple [str , HttpClient ]:
117
117
"""Initializes Split PDF Hook.
118
118
119
+ Adds a mock transport layer to the httpx client. This will return an
120
+ empty 200 response whenever the specified "dummy host" is used. The before_request
121
+ hook returns this request so the SDK always succeeds and jumps straight to
122
+ after_success, where we can await the split results.
123
+
119
124
Args:
120
125
base_url (str): URL of the API.
121
126
client (HttpClient): HTTP Client.
122
127
123
128
Returns:
124
- Tuple[str, httpx.Session ]: The initialized SDK options.
129
+ Tuple[str, HttpClient ]: The initialized SDK options.
125
130
"""
126
- self .client = client
127
- return base_url , client
131
+ class DummyTransport (httpx .BaseTransport ):
132
+ def __init__ (self , base_transport : httpx .BaseTransport ):
133
+ self .base_transport = base_transport
134
+
135
+ def handle_request (self , request : httpx .Request ) -> httpx .Response :
136
+ # Return an empty 200 response if we send a request to this dummy host
137
+ if request .method == "GET" and request .url .host == "no-op" :
138
+ return httpx .Response (status_code = 200 , content = b'' )
139
+
140
+ # Otherwise, pass the request to the default transport
141
+ return self .base_transport .handle_request (request )
142
+
143
+ # Explicit cast to httpx.Client to avoid a typing error
144
+ httpx_client = cast (httpx .Client , client )
145
+
146
+ # pylint: disable=protected-access
147
+ httpx_client ._transport = DummyTransport (httpx_client ._transport )
148
+
149
+ self .client = httpx_client
150
+ return base_url , self .client
128
151
129
152
# pylint: disable=too-many-return-statements
130
153
def before_request (
@@ -289,7 +312,7 @@ async def call_api_partial(page):
289
312
290
313
# Return a dummy request for the SDK to use
291
314
# This allows us to skip right to the AfterRequestHook and await all the calls
292
- dummy_request = httpx .Request ("GET" , "https ://httpbin.org/status/200 " )
315
+ dummy_request = httpx .Request ("GET" , "http ://no-op " )
293
316
294
317
return dummy_request
295
318
0 commit comments