@@ -249,37 +249,24 @@ extension NetworkSession {
249249 @discardableResult
250250 public func request( endpoint: Endpoint ) async throws ( NetworkError) -> Data {
251251 let endpointPath = await endpoint. path. resolveUrl ( )
252- let baseUrl = await baseUrl. resolveUrl ( )
253252 let url : URL
254-
255- // Check if endpointPath is absolute
256- let endpointHasScheme : Bool = if let endpointPath,
257- let endpointPathScheme = endpointPath. scheme,
258- !endpointPathScheme. isEmpty { true } else { false }
259-
260- let endpointHasHost : Bool = if let endpointPath,
261- let endpointPathHost = endpointPath. host,
262- !endpointPathHost. isEmpty { true } else { false }
263-
264- // Check if baseUrl is resolvable
265- let baseUrlHasScheme : Bool = if let baseUrl,
266- let baseUrlScheme = baseUrl. scheme,
267- !baseUrlScheme. isEmpty { true } else { false }
268-
269- let baseUrlHasHost : Bool = if let baseUrl,
270- let baseUrlHost = baseUrl. host,
271- !baseUrlHost. isEmpty { true } else { false }
272-
273- let endpointIsAbsolutePath = endpointHasScheme && endpointHasHost
274- if endpointIsAbsolutePath, let endpointPath {
253+
254+ // If endpoint already contains an absolute path, do not concatenate
255+ // with baseURL and use that instead
256+ if let endpointPath, endpointPath. isAbsolute {
275257 url = endpointPath
276258 } else {
259+ // If endpoint has only relative path, resolve it over baseURL
260+ let baseUrl = await baseUrl. resolveUrl ( )
277261 let endpointResolvedUrl = await endpoint. url ( on: baseUrl)
278- if let endpointResolvedUrl {
279- url = endpointResolvedUrl
280- } else {
262+
263+ // If neither endpoint nor baseURL are specified, URL cannot be resolved
264+ guard let endpointResolvedUrl else {
281265 throw URLError ( . badURL) . asNetworkError ( )
282266 }
267+
268+ // URL is resolved
269+ url = endpointResolvedUrl
283270 }
284271
285272 // url + method
0 commit comments