Skip to content

[wip] streaming uploads #6161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/Basics/HTTPClient/HTTPClientError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public enum HTTPClientError: Error, Equatable {
case circuitBreakerTriggered
case responseTooLarge(Int64)
case downloadError(String)
case uploadError(String)
}
38 changes: 37 additions & 1 deletion Sources/Basics/HTTPClient/LegacyHTTPClientRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,46 @@ public struct LegacyHTTPClientRequest {
)
}

// upload request
public static func upload(
method: UploadMethod = .post,
url: URL,
headers: HTTPClientHeaders = .init(),
options: Options = .init(),
streamProvider: @escaping () throws -> LegacyHTTPClientRequest.UploadStream?
) -> Self {
self.init(
kind: .upload(method, streamProvider: streamProvider),
url: url,
headers: headers,
body: nil,
options: options
)
}

public var method: HTTPMethod {
switch self.kind {
case .generic(let method):
return method
case .download:
return .get
case .upload(let method, _):
switch method {
case .post:
return .post
case .put:
return .put
}
}
}

public typealias FileMoveCompletion = @Sendable (Error?) -> ()
public typealias FileMoveCompletion = @Sendable (Error?)
-> Void

public enum Kind {
case generic(HTTPMethod)
case download(fileSystem: FileSystem, destination: AbsolutePath)
case upload(UploadMethod, streamProvider: () throws -> LegacyHTTPClientRequest.UploadStream?)
}

public struct Options {
Expand Down Expand Up @@ -110,4 +136,14 @@ public struct LegacyHTTPClientRequest {
public var circuitBreakerStrategy: HTTPClientCircuitBreakerStrategy?
public var callbackQueue: DispatchQueue?
}

public enum UploadMethod {
case post
case put
}

public enum UploadStream {
case chunk(Data)
case stream(InputStream)
}
}
Loading