forked from apple/swift-http-api-proposal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTPClientRequestBody+Data.swift
More file actions
32 lines (30 loc) · 1.06 KB
/
Copy pathHTTPClientRequestBody+Data.swift
File metadata and controls
32 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift HTTP API Proposal open source project
//
// Copyright (c) 2026 Apple Inc. and the Swift HTTP API Proposal project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
#if canImport(FoundationEssentials)
public import struct FoundationEssentials.Data
#else
public import struct Foundation.Data
#endif
@available(anyAppleOS 26.0, *)
extension HTTPClientRequestBody where Writer: ~Copyable {
/// Creates a seekable request body from `Data`.
///
/// - Parameter data: The data to send as the request body.
public static func data(_ data: Data) -> Self {
.seekable(knownLength: Int64(data.count)) { offset, writer in
var writer = writer
try await writer.write(data.span.extracting(droppingFirst: Int(offset)))
return nil
}
}
}