• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / supabase-swift / 16836901907

08 Aug 2025 05:43PM UTC coverage: 77.009% (-0.4%) from 77.442%
16836901907

Pull #766

github

web-flow
Merge bfcc4cf78 into f5b5ee3fa
Pull Request #766: feat: adopt new HTTP layer from OpenAPIRuntime and migrate Functions to it

130 of 185 new or added lines in 5 files covered. (70.27%)

3 existing lines in 1 file now uncovered.

5557 of 7216 relevant lines covered (77.01%)

22.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.56
/Sources/Helpers/HTTP/Client.swift
1
import HTTPTypes
2
import OpenAPIRuntime
3

4
#if canImport(Darwin)
5
  import struct Foundation.URL
6
  import struct Foundation.URLComponents
7
#else
8
  @preconcurrency import struct Foundation.URL
9
  @preconcurrency import struct Foundation.URLComponents
10
#endif
11

12
/// A client that can send HTTP requests and receive HTTP responses.
13
package struct Client: Sendable {
14

15
  /// The URL of the server, used as the base URL for requests made by the
16
  /// client.
17
  let serverURL: URL
18

19
  /// A type capable of sending HTTP requests and receiving HTTP responses.
20
  var transport: any ClientTransport
21

22
  /// The middlewares to be invoked before the transport.
23
  var middlewares: [any ClientMiddleware]
24

25
  /// Creates a new client.
26
  package init(
27
    serverURL: URL,
28
    transport: any ClientTransport,
29
    middlewares: [any ClientMiddleware] = []
30
  ) {
18✔
31
    self.serverURL = serverURL.baseURL
18✔
32
    self.transport = transport
18✔
33
    self.middlewares = middlewares
18✔
34
  }
18✔
35

36
  /// Sends the HTTP request and returns the HTTP response.
37
  ///
38
  /// - Parameters:
39
  ///   - request: The HTTP request to send.
40
  ///   - body: The HTTP request body to send.
41
  /// - Returns: The HTTP response and its body.
42
  /// - Throws: An error if any part of the HTTP operation process fails.
43
  package func send(
44
    _ request: HTTPTypes.HTTPRequest,
45
    body: HTTPBody? = nil
46
  ) async throws -> (HTTPTypes.HTTPResponse, HTTPBody) {
15✔
47
    let baseURL = serverURL
15✔
48
    var next:
15✔
49
      @Sendable (HTTPTypes.HTTPRequest, HTTPBody?, URL) async throws -> (
15✔
50
        HTTPTypes.HTTPResponse, HTTPBody
15✔
51
      ) = {
15✔
52
        (_request, _body, _url) in
15✔
53
        let (response, body) = try await transport.send(
15✔
54
          _request,
15✔
55
          body: _body,
15✔
56
          baseURL: _url,
15✔
57
          operationID: ""
15✔
58
        )
15✔
59
        return (response, body ?? HTTPBody())
9✔
60
      }
15✔
61
    for middleware in middlewares.reversed() {
15✔
NEW
62
      let tmp = next
×
NEW
63
      next = { (_request, _body, _url) in
×
NEW
64
        let (response, body) = try await middleware.intercept(
×
NEW
65
          _request,
×
NEW
66
          body: _body,
×
NEW
67
          baseURL: _url,
×
NEW
68
          operationID: "",
×
NEW
69
          next: tmp
×
NEW
70
        )
×
NEW
71
        return (response, body ?? HTTPBody())
×
NEW
72
      }
×
73
    }
15✔
74
    return try await next(request, body, baseURL)
15✔
75
  }
15✔
76
}
77

78
extension URL {
79
  /// Returns a new URL which contains only `{scheme}://{host}:{port}`.
80
  fileprivate var baseURL: URL {
18✔
81
    guard let components = URLComponents(string: self.absoluteString) else { return self }
18✔
82

18✔
83
    var newComponents = URLComponents()
18✔
84
    newComponents.scheme = components.scheme
18✔
85
    newComponents.host = components.host
18✔
86
    newComponents.port = components.port
18✔
87

18✔
88
    return newComponents.url ?? self
18✔
89
  }
18✔
90
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc