mirror of
https://github.com/apple/swift-http-types
synced 2026-11-30 05:18:47 +00:00
[CI] Make all CI checks green
# Motivation We just adopted GH actions and want to make sure all the CI checks are green. # Modification This PR makes the necessary changes to pass all checks. Including: - Adding a licenseignore file - Moving `swift-format` and adopting the config that we use in all other swift on server repos. # Result Green CI.
This commit is contained in:
1 parent
70cda1b770
commit
f3d9ec3eef
29 files changed
+541
-207
No files matched your search
@@ -22,8 +22,9 @@ extension HTTPRequest {
|
||||
public var url: URL? {
|
||||
get {
|
||||
if let schemeField = self.pseudoHeaderFields.scheme,
|
||||
let authorityField = self.pseudoHeaderFields.authority,
|
||||
let pathField = self.pseudoHeaderFields.path {
|
||||
let authorityField = self.pseudoHeaderFields.authority,
|
||||
let pathField = self.pseudoHeaderFields.path
|
||||
{
|
||||
return schemeField.withUnsafeBytesOfValue { scheme in
|
||||
authorityField.withUnsafeBytesOfValue { authority in
|
||||
pathField.withUnsafeBytesOfValue { path in
|
||||
@@ -60,7 +61,13 @@ extension HTTPRequest {
|
||||
let authorityString = authority.map { String(decoding: $0, as: UTF8.self) }
|
||||
let pathString = String(decoding: path, as: UTF8.self)
|
||||
|
||||
self.init(method: method, scheme: schemeString, authority: authorityString, path: pathString, headerFields: headerFields)
|
||||
self.init(
|
||||
method: method,
|
||||
scheme: schemeString,
|
||||
authority: authorityString,
|
||||
path: pathString,
|
||||
headerFields: headerFields
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +81,14 @@ extension URL {
|
||||
buffer.append(contentsOf: path)
|
||||
|
||||
if let url = buffer.withUnsafeBytes({ buffer in
|
||||
CFURLCreateAbsoluteURLWithBytes(kCFAllocatorDefault, buffer.baseAddress, buffer.count, CFStringBuiltInEncodings.ASCII.rawValue, nil, false).map { unsafeBitCast($0, to: NSURL.self) as URL }
|
||||
CFURLCreateAbsoluteURLWithBytes(
|
||||
kCFAllocatorDefault,
|
||||
buffer.baseAddress,
|
||||
buffer.count,
|
||||
CFStringBuiltInEncodings.ASCII.rawValue,
|
||||
nil,
|
||||
false
|
||||
).map { unsafeBitCast($0, to: NSURL.self) as URL }
|
||||
}) {
|
||||
self = url
|
||||
} else {
|
||||
@@ -96,7 +110,7 @@ extension URL {
|
||||
}
|
||||
|
||||
func bufferSlice(_ range: CFRange) -> UnsafeMutableBufferPointer<UInt8> {
|
||||
UnsafeMutableBufferPointer(rebasing: buffer[range.location ..< range.location + range.length])
|
||||
UnsafeMutableBufferPointer(rebasing: buffer[range.location..<range.location + range.length])
|
||||
}
|
||||
|
||||
let schemeRange = CFURLGetByteRangeForComponent(url, .scheme, nil)
|
||||
@@ -124,7 +138,9 @@ extension URL {
|
||||
let pathBuffer = bufferSlice(requestPathRange)
|
||||
path = [UInt8](unsafeUninitializedCapacity: pathBuffer.count + 1) { buffer, initializedCount in
|
||||
buffer[0] = 0x2F
|
||||
UnsafeMutableRawBufferPointer(UnsafeMutableBufferPointer(rebasing: buffer[1...])).copyMemory(from: UnsafeRawBufferPointer(pathBuffer))
|
||||
UnsafeMutableRawBufferPointer(UnsafeMutableBufferPointer(rebasing: buffer[1...])).copyMemory(
|
||||
from: UnsafeRawBufferPointer(pathBuffer)
|
||||
)
|
||||
initializedCount = pathBuffer.count + 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,8 @@ extension HTTPField {
|
||||
if isoLatin1Value.isASCII {
|
||||
self.init(name: name, value: isoLatin1Value)
|
||||
} else {
|
||||
self = withUnsafeTemporaryAllocation(of: UInt8.self, capacity: isoLatin1Value.unicodeScalars.count) { buffer in
|
||||
self = withUnsafeTemporaryAllocation(of: UInt8.self, capacity: isoLatin1Value.unicodeScalars.count) {
|
||||
buffer in
|
||||
for (index, scalar) in isoLatin1Value.unicodeScalars.enumerated() {
|
||||
if scalar.value > UInt8.max {
|
||||
buffer[index] = 0x20
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
import Foundation
|
||||
import HTTPTypes
|
||||
|
||||
#if canImport(FoundationNetworking)
|
||||
import FoundationNetworking
|
||||
#endif
|
||||
@@ -49,7 +50,7 @@ extension URLRequest {
|
||||
/// Convert the `URLRequest` into an `HTTPRequest`.
|
||||
public var httpRequest: HTTPRequest? {
|
||||
guard let method = HTTPRequest.Method(self.httpMethod ?? "GET"),
|
||||
let url
|
||||
let url
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
import Foundation
|
||||
import HTTPTypes
|
||||
|
||||
#if canImport(FoundationNetworking)
|
||||
import FoundationNetworking
|
||||
#endif
|
||||
@@ -42,7 +43,7 @@ extension HTTPURLResponse {
|
||||
|
||||
/// Convert the `HTTPURLResponse` into an `HTTPResponse`.
|
||||
public var httpResponse: HTTPResponse? {
|
||||
guard (0 ... 999).contains(self.statusCode) else {
|
||||
guard (0...999).contains(self.statusCode) else {
|
||||
return nil
|
||||
}
|
||||
var response = HTTPResponse(status: .init(code: self.statusCode))
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
import Foundation
|
||||
import HTTPTypes
|
||||
|
||||
#if canImport(FoundationNetworking)
|
||||
import FoundationNetworking
|
||||
#endif
|
||||
@@ -44,7 +45,7 @@ private enum HTTPTypeConversionError: Error {
|
||||
|
||||
#endif
|
||||
|
||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS) || compiler(>=6)
|
||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || compiler(>=6) || (compiler(>=6) && os(visionOS))
|
||||
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
extension URLSession {
|
||||
@@ -53,7 +54,10 @@ extension URLSession {
|
||||
/// - Parameter request: The `HTTPRequest` for which to load data.
|
||||
/// - Parameter delegate: Task-specific delegate.
|
||||
/// - Returns: Data and response.
|
||||
public func data(for request: HTTPRequest, delegate: URLSessionTaskDelegate? = nil) async throws -> (Data, HTTPResponse) {
|
||||
public func data(
|
||||
for request: HTTPRequest,
|
||||
delegate: URLSessionTaskDelegate? = nil
|
||||
) async throws -> (Data, HTTPResponse) {
|
||||
guard let urlRequest = URLRequest(httpRequest: request) else {
|
||||
throw HTTPTypeConversionError.failedToConvertHTTPRequestToURLRequest
|
||||
}
|
||||
@@ -70,7 +74,11 @@ extension URLSession {
|
||||
/// - Parameter fileURL: File to upload.
|
||||
/// - Parameter delegate: Task-specific delegate.
|
||||
/// - Returns: Data and response.
|
||||
public func upload(for request: HTTPRequest, fromFile fileURL: URL, delegate: URLSessionTaskDelegate? = nil) async throws -> (Data, HTTPResponse) {
|
||||
public func upload(
|
||||
for request: HTTPRequest,
|
||||
fromFile fileURL: URL,
|
||||
delegate: URLSessionTaskDelegate? = nil
|
||||
) async throws -> (Data, HTTPResponse) {
|
||||
guard let urlRequest = URLRequest(httpRequest: request) else {
|
||||
throw HTTPTypeConversionError.failedToConvertHTTPRequestToURLRequest
|
||||
}
|
||||
@@ -87,7 +95,11 @@ extension URLSession {
|
||||
/// - Parameter bodyData: Data to upload.
|
||||
/// - Parameter delegate: Task-specific delegate.
|
||||
/// - Returns: Data and response.
|
||||
public func upload(for request: HTTPRequest, from bodyData: Data, delegate: URLSessionTaskDelegate? = nil) async throws -> (Data, HTTPResponse) {
|
||||
public func upload(
|
||||
for request: HTTPRequest,
|
||||
from bodyData: Data,
|
||||
delegate: URLSessionTaskDelegate? = nil
|
||||
) async throws -> (Data, HTTPResponse) {
|
||||
guard let urlRequest = URLRequest(httpRequest: request) else {
|
||||
throw HTTPTypeConversionError.failedToConvertHTTPRequestToURLRequest
|
||||
}
|
||||
@@ -103,7 +115,10 @@ extension URLSession {
|
||||
/// - Parameter request: The `HTTPRequest` for which to download.
|
||||
/// - Parameter delegate: Task-specific delegate.
|
||||
/// - Returns: Downloaded file URL and response. The file will not be removed automatically.
|
||||
public func download(for request: HTTPRequest, delegate: URLSessionTaskDelegate? = nil) async throws -> (URL, HTTPResponse) {
|
||||
public func download(
|
||||
for request: HTTPRequest,
|
||||
delegate: URLSessionTaskDelegate? = nil
|
||||
) async throws -> (URL, HTTPResponse) {
|
||||
guard let urlRequest = URLRequest(httpRequest: request) else {
|
||||
throw HTTPTypeConversionError.failedToConvertHTTPRequestToURLRequest
|
||||
}
|
||||
@@ -114,13 +129,16 @@ extension URLSession {
|
||||
return (location, response)
|
||||
}
|
||||
|
||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
|
||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || (compiler(>=6) && os(visionOS))
|
||||
/// Returns a byte stream that conforms to AsyncSequence protocol.
|
||||
///
|
||||
/// - Parameter request: The `HTTPRequest` for which to load data.
|
||||
/// - Parameter delegate: Task-specific delegate.
|
||||
/// - Returns: Data stream and response.
|
||||
public func bytes(for request: HTTPRequest, delegate: URLSessionTaskDelegate? = nil) async throws -> (AsyncBytes, HTTPResponse) {
|
||||
public func bytes(
|
||||
for request: HTTPRequest,
|
||||
delegate: URLSessionTaskDelegate? = nil
|
||||
) async throws -> (AsyncBytes, HTTPResponse) {
|
||||
guard let urlRequest = URLRequest(httpRequest: request) else {
|
||||
throw HTTPTypeConversionError.failedToConvertHTTPRequestToURLRequest
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user