Skip to content

Commit 09f7326

Browse files
committed
Core: updatating async-http-client instead of foundation urlsession
1 parent 19dc2bd commit 09f7326

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+371
-312
lines changed

Package.resolved

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ let package = Package(
1616
.library(name: "Github", targets: ["Github"])
1717
],
1818
dependencies: [
19-
.package(url: "https://github.com/apple/swift-http-types", .upToNextMajor(from: "0.1.1"))
19+
.package(url: "https://github.com/apple/swift-http-types", .upToNextMajor(from: "0.1.1")),
20+
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.9.0")
2021
],
2122
targets: [
2223

@@ -42,6 +43,7 @@ let package = Package(
4243
dependencies: [
4344
.product(name: "HTTPTypes", package: "swift-http-types"),
4445
.product(name: "HTTPTypesFoundation", package: "swift-http-types"),
46+
.product(name: "AsyncHTTPClient", package: "async-http-client"),
4547
]
4648
),
4749
.testTarget(

Sources/Github/GitHubAPI/Activity/Notifications/Notifications.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
//
77

88
import Foundation
9-
#if canImport(FoundationNetworking)
10-
import FoundationNetworking
11-
#endif
129
import HttpClient
1310
import HTTPTypes
1411

@@ -53,7 +50,7 @@ extension GitHub {
5350

5451
let request = HTTPRequest(method: method, url: endpoint, queries: queries, headers: headers)
5552

56-
let (data, _) = try await session.data(for: request)
53+
let (data, _) = try await execute( request)
5754

5855
let notifications = try decode([Notification].self, from: data)
5956

Sources/Github/GitHubAPI/Activity/Starring/Stargazers.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
//
77

88
import Foundation
9-
#if canImport(FoundationNetworking)
10-
import FoundationNetworking
11-
#endif
129
import HttpClient
1310
import HTTPTypes
1411

@@ -38,7 +35,7 @@ extension GitHub {
3835

3936
let request = HTTPRequest(method: method, url: endpoint, queries: queries, headers: headers)
4037

41-
let (data, _) = try await session.data(for: request)
38+
let (data, _) = try await execute( request)
4239

4340
let users = try decode([User].self, from: data)
4441

Sources/Github/GitHubAPI/Collaborators/Collaborators.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
//
77

88
import Foundation
9-
#if canImport(FoundationNetworking)
10-
import FoundationNetworking
11-
#endif
129
import HttpClient
1310
import HTTPTypes
1411

@@ -50,7 +47,7 @@ extension GitHub {
5047

5148
let request = HTTPRequest(method: method, url: endpoint, queries: queries, headers: headers)
5249

53-
let (data, _) = try await session.data(for: request)
50+
let (data, _) = try await execute( request)
5451

5552
let collaborators = try decode([Collaborator].self, from: data)
5653

Sources/Github/GitHubAPI/Discussions/DiscussionRequest.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
//
77

88
import Foundation
9-
#if canImport(FoundationNetworking)
10-
import FoundationNetworking
11-
#endif
129
import HttpClient
1310
import HTTPTypes
1411

@@ -62,11 +59,11 @@ extension GitHub {
6259
}
6360
"""
6461

65-
let httpRequest = HTTPRequest(method: method, url: endpoint, queries: [:], headers: headers)
66-
var urlRequest = URLRequest(httpRequest: httpRequest)!
67-
urlRequest.httpBody = try JSONEncoder().encode(["query": query])
62+
let request = HTTPRequest(method: method, url: endpoint, queries: [:], headers: headers)
6863

69-
let (data, _) = try await session.data(for: urlRequest)
64+
let bodyData = try JSONEncoder().encode(["query": query])
65+
66+
let (data, _) = try await execute(request, body: bodyData)
7067
let response = try decode(DiscussionResponse.self, from: data)
7168

7269
return response.discussion

Sources/Github/GitHubAPI/Discussions/Discussions.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
//
77

88
import Foundation
9-
#if canImport(FoundationNetworking)
10-
import FoundationNetworking
11-
#endif
129
import HttpClient
1310
import HTTPTypes
1411

@@ -73,11 +70,10 @@ extension GitHub {
7370
}
7471
"""
7572

76-
let httpRequest = HTTPRequest(method: method, url: endpoint, queries: [:], headers: headers)
77-
var urlRequest = URLRequest(httpRequest: httpRequest)!
78-
urlRequest.httpBody = try JSONEncoder().encode(["query": query])
79-
80-
let (data, _) = try await session.data(for: urlRequest)
73+
let request = HTTPRequest(method: method, url: endpoint, queries: [:], headers: headers)
74+
let body = try JSONEncoder().encode(["query": query])
75+
76+
let (data, _) = try await execute(request, body: body)
8177
let response = try decode(DiscussionsResponse.self, from: data)
8278

8379
return response.discussions

Sources/Github/GitHubAPI/Gitignore/AllGitignoreTemplateNames.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
//
77

88
import Foundation
9-
#if canImport(FoundationNetworking)
10-
import FoundationNetworking
11-
#endif
129
import HttpClient
1310
import HTTPTypes
1411

@@ -24,7 +21,7 @@ extension GitHub {
2421

2522
let request = HTTPRequest(method: method, url: endpoint, queries: [:], headers: headers)
2623

27-
let (data, _) = try await session.data(for: request)
24+
let (data, _) = try await execute( request)
2825

2926
let templates = try decode([String].self, from: data)
3027

Sources/Github/GitHubAPI/Gitignore/GetGitignoreTemplate.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
//
77

88
import Foundation
9-
#if canImport(FoundationNetworking)
10-
import FoundationNetworking
11-
#endif
129
import HttpClient
1310
import HTTPTypes
1411

@@ -26,7 +23,7 @@ extension GitHub {
2623

2724
let request = HTTPRequest(method: method, url: endpoint, queries: [:], headers: headers)
2825

29-
let (data, _) = try await session.data(for: request)
26+
let (data, _) = try await execute( request)
3027

3128
let template = try decode(GitignoreTemplate.self, from: data)
3229

Sources/Github/GitHubAPI/Issue/Comments.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
//
77

88
import Foundation
9-
#if canImport(FoundationNetworking)
10-
import FoundationNetworking
11-
#endif
129
import HttpClient
1310
import HTTPTypes
1411

@@ -48,7 +45,7 @@ extension GitHub {
4845

4946
let request = HTTPRequest(method: method, url: endpoint, queries: queries, headers: headers)
5047

51-
let (data, _) = try await session.data(for: request)
48+
let (data, _) = try await execute( request)
5249

5350
let comments = try decode([Comment].self, from: data)
5451

0 commit comments

Comments
 (0)