From f3d9ec3eefe96c83b74f13f7a510970934ad7a8d Mon Sep 17 00:00:00 2001 From: Franz Busch Date: Wed, 23 Oct 2024 13:13:37 +0200 Subject: [PATCH 1/5] [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. --- .github/workflows/main.yml | 12 +- .github/workflows/pull_request.yml | 12 +- .github/workflows/scheduled.yml | 12 +- .licenseignore | 43 ++++++ .swift-format | 62 ++++++++ .swiftformat | 21 --- .../HTTPFieldsBenchmarks/Benchmarks.swift | 12 +- Benchmarks/Package.swift | 6 +- ...TPFields.init(dictionaryLiteral:).p90.json | 3 + ...TPFields.init(dictionaryLiteral:).p90.json | 3 + ...TPFields.init(dictionaryLiteral:).p90.json | 3 + ...TPFields.init(dictionaryLiteral:).p90.json | 3 + ...TPFields.init(dictionaryLiteral:).p90.json | 3 + Package.swift | 9 +- Sources/HTTPTypes/HTTPField.swift | 40 +++-- Sources/HTTPTypes/HTTPFieldName.swift | 143 +++++++++++++----- Sources/HTTPTypes/HTTPFields.swift | 31 ++-- Sources/HTTPTypes/HTTPParsedFields.swift | 36 ++++- Sources/HTTPTypes/HTTPRequest.swift | 47 ++++-- Sources/HTTPTypes/HTTPResponse.swift | 70 ++++++--- Sources/HTTPTypes/ISOLatin1String.swift | 4 +- .../HTTPTypesFoundation/HTTPRequest+URL.swift | 28 +++- .../HTTPTypes+ISOLatin1.swift | 3 +- .../URLRequest+HTTPTypes.swift | 3 +- .../URLResponse+HTTPTypes.swift | 3 +- .../URLSession+HTTPTypes.swift | 32 +++- .../HTTPTypesFoundationTests.swift | 18 ++- Tests/HTTPTypesTests/HTTPTypesTests.swift | 84 ++++++---- scripts/preview_docc.sh | 2 +- 29 files changed, 541 insertions(+), 207 deletions(-) create mode 100644 .licenseignore create mode 100644 .swift-format delete mode 100644 .swiftformat create mode 100644 Benchmarks/Thresholds/5.10/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json create mode 100644 Benchmarks/Thresholds/5.9/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json create mode 100644 Benchmarks/Thresholds/6.0/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json create mode 100644 Benchmarks/Thresholds/nightly-6.0/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json create mode 100644 Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4191b32..a16ffc8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,12 +14,12 @@ jobs: linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error" - windows_6_0_enabled: true - windows_nightly_6_0_enabled: true - windows_nightly_main_enabled: true - windows_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" - windows_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" - windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + + benchmarks: + name: Benchmarks + uses: apple/swift-nio/.github/workflows/benchmarks.yml@main + with: + benchmark_package_path: "Benchmarks" cxx-interop: name: Cxx interop diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index b7b4b0c..6ed21cc 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -20,12 +20,12 @@ jobs: linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error" - windows_6_0_enabled: true - windows_nightly_6_0_enabled: true - windows_nightly_main_enabled: true - windows_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" - windows_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" - windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + + benchmarks: + name: Benchmarks + uses: apple/swift-nio/.github/workflows/benchmarks.yml@main + with: + benchmark_package_path: "Benchmarks" cxx-interop: name: Cxx interop diff --git a/.github/workflows/scheduled.yml b/.github/workflows/scheduled.yml index f26f8f1..b9db48f 100644 --- a/.github/workflows/scheduled.yml +++ b/.github/workflows/scheduled.yml @@ -14,12 +14,12 @@ jobs: linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error" - windows_6_0_enabled: true - windows_nightly_6_0_enabled: true - windows_nightly_main_enabled: true - windows_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" - windows_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" - windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + + benchmarks: + name: Benchmarks + uses: apple/swift-nio/.github/workflows/benchmarks.yml@main + with: + benchmark_package_path: "Benchmarks" cxx-interop: name: Cxx interop diff --git a/.licenseignore b/.licenseignore new file mode 100644 index 0000000..41cebc9 --- /dev/null +++ b/.licenseignore @@ -0,0 +1,43 @@ +.gitignore +**/.gitignore +.licenseignore +.gitattributes +.git-blame-ignore-revs +.mailfilter +.mailmap +.spi.yml +.swift-format +.editorconfig +.github/* +*.md +*.txt +*.yml +*.yaml +*.json +Package.swift +**/Package.swift +Package@-*.swift +**/Package@-*.swift +Package.resolved +**/Package.resolved +Makefile +*.modulemap +**/*.modulemap +**/*.docc/* +*.xcprivacy +**/*.xcprivacy +*.symlink +**/*.symlink +Dockerfile +**/Dockerfile +Sources/CMakeLists.txt +Sources/SwiftASN1/CMakeLists.txt +dev/alloc-limits-from-test-output +dev/boxed-existentials.d +dev/git.commit.template +dev/lldb-smoker +dev/make-single-file-spm +dev/malloc-aggregation.d +dev/update-alloc-limits-to-last-completed-ci-build +Benchmarks/Benchmarks/SwiftASN1Benchmark/ca-certificates/*.crt +Benchmarks/Benchmarks/SwiftASN1Benchmark/ca-certificates/*/*.crt diff --git a/.swift-format b/.swift-format new file mode 100644 index 0000000..7fa06fb --- /dev/null +++ b/.swift-format @@ -0,0 +1,62 @@ +{ + "version" : 1, + "indentation" : { + "spaces" : 4 + }, + "tabWidth" : 4, + "fileScopedDeclarationPrivacy" : { + "accessLevel" : "private" + }, + "spacesAroundRangeFormationOperators" : false, + "indentConditionalCompilationBlocks" : false, + "indentSwitchCaseLabels" : false, + "lineBreakAroundMultilineExpressionChainComponents" : false, + "lineBreakBeforeControlFlowKeywords" : false, + "lineBreakBeforeEachArgument" : true, + "lineBreakBeforeEachGenericRequirement" : true, + "lineLength" : 120, + "maximumBlankLines" : 1, + "respectsExistingLineBreaks" : true, + "prioritizeKeepingFunctionOutputTogether" : true, + "rules" : { + "AllPublicDeclarationsHaveDocumentation" : false, + "AlwaysUseLiteralForEmptyCollectionInit" : false, + "AlwaysUseLowerCamelCase" : false, + "AmbiguousTrailingClosureOverload" : true, + "BeginDocumentationCommentWithOneLineSummary" : false, + "DoNotUseSemicolons" : true, + "DontRepeatTypeInStaticProperties" : true, + "FileScopedDeclarationPrivacy" : true, + "FullyIndirectEnum" : true, + "GroupNumericLiterals" : true, + "IdentifiersMustBeASCII" : true, + "NeverForceUnwrap" : false, + "NeverUseForceTry" : false, + "NeverUseImplicitlyUnwrappedOptionals" : false, + "NoAccessLevelOnExtensionDeclaration" : true, + "NoAssignmentInExpressions" : true, + "NoBlockComments" : true, + "NoCasesWithOnlyFallthrough" : true, + "NoEmptyTrailingClosureParentheses" : true, + "NoLabelsInCasePatterns" : true, + "NoLeadingUnderscores" : false, + "NoParensAroundConditions" : true, + "NoVoidReturnOnFunctionSignature" : true, + "OmitExplicitReturns" : true, + "OneCasePerLine" : true, + "OneVariableDeclarationPerLine" : true, + "OnlyOneTrailingClosureArgument" : true, + "OrderedImports" : true, + "ReplaceForEachWithForLoop" : true, + "ReturnVoidInsteadOfEmptyTuple" : true, + "UseEarlyExits" : false, + "UseExplicitNilCheckInConditions" : false, + "UseLetInEveryBoundCaseVariable" : false, + "UseShorthandTypeNames" : true, + "UseSingleLinePropertyGetter" : false, + "UseSynthesizedInitializer" : false, + "UseTripleSlashForDocumentationComments" : true, + "UseWhereClausesInForLoops" : false, + "ValidateDocumentationComments" : false + } +} diff --git a/.swiftformat b/.swiftformat deleted file mode 100644 index aceb57f..0000000 --- a/.swiftformat +++ /dev/null @@ -1,21 +0,0 @@ ---swiftversion 5.7 - -# file options - ---exclude .build - -# format options - ---ifdef no-indent ---indent 4 ---extensionacl on-declarations ---patternlet inline ---self insert ---stripunusedargs closure-only ---wraparguments before-first - -# rules - ---disable andOperator ---disable blankLinesAroundMark ---disable wrapMultilineStatementBraces diff --git a/Benchmarks/Benchmarks/HTTPFieldsBenchmarks/Benchmarks.swift b/Benchmarks/Benchmarks/HTTPFieldsBenchmarks/Benchmarks.swift index 36f8b71..8fb9e34 100644 --- a/Benchmarks/Benchmarks/HTTPFieldsBenchmarks/Benchmarks.swift +++ b/Benchmarks/Benchmarks/HTTPFieldsBenchmarks/Benchmarks.swift @@ -16,8 +16,18 @@ import Benchmark import HTTPTypes let benchmarks = { + let defaultMetrics: [BenchmarkMetric] = [ + .mallocCountTotal + ] + Benchmark( - "Initialize HTTPFields from Dictionary Literal" + "HTTPFields.init(dictionaryLiteral:)", + configuration: .init( + metrics: defaultMetrics, + scalingFactor: .kilo, + maxDuration: .seconds(10_000_000), + maxIterations: 10 + ) ) { _ in let fiels: HTTPFields = [ .contentType: "application/json", diff --git a/Benchmarks/Package.swift b/Benchmarks/Package.swift index efa8540..65002a8 100644 --- a/Benchmarks/Package.swift +++ b/Benchmarks/Package.swift @@ -5,7 +5,7 @@ import PackageDescription let package = Package( name: "Benchmarks", platforms: [ - .macOS(.v13), + .macOS(.v13) ], dependencies: [ .package(path: "../"), @@ -20,8 +20,8 @@ let package = Package( ], path: "Benchmarks/HTTPFieldsBenchmarks", plugins: [ - .plugin(name: "BenchmarkPlugin", package: "package-benchmark"), + .plugin(name: "BenchmarkPlugin", package: "package-benchmark") ] - ), + ) ] ) diff --git a/Benchmarks/Thresholds/5.10/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json b/Benchmarks/Thresholds/5.10/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json new file mode 100644 index 0000000..bc880db --- /dev/null +++ b/Benchmarks/Thresholds/5.10/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json @@ -0,0 +1,3 @@ +{ + "mallocCountTotal" : 14 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/5.9/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json b/Benchmarks/Thresholds/5.9/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json new file mode 100644 index 0000000..bc880db --- /dev/null +++ b/Benchmarks/Thresholds/5.9/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json @@ -0,0 +1,3 @@ +{ + "mallocCountTotal" : 14 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.0/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json b/Benchmarks/Thresholds/6.0/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json new file mode 100644 index 0000000..bc880db --- /dev/null +++ b/Benchmarks/Thresholds/6.0/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json @@ -0,0 +1,3 @@ +{ + "mallocCountTotal" : 14 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-6.0/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json b/Benchmarks/Thresholds/nightly-6.0/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json new file mode 100644 index 0000000..bc880db --- /dev/null +++ b/Benchmarks/Thresholds/nightly-6.0/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json @@ -0,0 +1,3 @@ +{ + "mallocCountTotal" : 14 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json new file mode 100644 index 0000000..bc880db --- /dev/null +++ b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json @@ -0,0 +1,3 @@ +{ + "mallocCountTotal" : 14 +} \ No newline at end of file diff --git a/Package.swift b/Package.swift index b52ea72..575ce46 100644 --- a/Package.swift +++ b/Package.swift @@ -8,27 +8,24 @@ let package = Package( .library(name: "HTTPTypes", targets: ["HTTPTypes"]), .library(name: "HTTPTypesFoundation", targets: ["HTTPTypesFoundation"]), ], - dependencies: [ - .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0"), - ], targets: [ .target(name: "HTTPTypes"), .target( name: "HTTPTypesFoundation", dependencies: [ - "HTTPTypes", + "HTTPTypes" ] ), .testTarget( name: "HTTPTypesTests", dependencies: [ - "HTTPTypes", + "HTTPTypes" ] ), .testTarget( name: "HTTPTypesFoundationTests", dependencies: [ - "HTTPTypesFoundation", + "HTTPTypesFoundation" ] ), ] diff --git a/Sources/HTTPTypes/HTTPField.swift b/Sources/HTTPTypes/HTTPField.swift index 82fd9a7..8645aa9 100644 --- a/Sources/HTTPTypes/HTTPField.swift +++ b/Sources/HTTPTypes/HTTPField.swift @@ -112,7 +112,9 @@ public struct HTTPField: Sendable, Hashable { /// /// - Parameter body: The closure to be invoked with the buffer. /// - Returns: Result of the `body` closure. - public func withUnsafeBytesOfValue(_ body: (UnsafeBufferPointer) throws -> Result) rethrows -> Result { + public func withUnsafeBytesOfValue( + _ body: (UnsafeBufferPointer) throws -> Result + ) rethrows -> Result { try self.rawValue.withUnsafeBytes(body) } @@ -135,7 +137,7 @@ public struct HTTPField: Sendable, Hashable { switch byte { case 0x09, 0x20: break - case 0x21 ... 0x7E, 0x80 ... 0xFF: + case 0x21...0x7E, 0x80...0xFF: break default: return false @@ -161,13 +163,15 @@ public struct HTTPField: Sendable, Hashable { switch byte { case 0x09, 0x20: return byte - case 0x21 ... 0x7E, 0x80 ... 0xFF: + case 0x21...0x7E, 0x80...0xFF: return byte default: return 0x20 } } - let trimmed = bytes.reversed().drop { $0 == 0x09 || $0 == 0x20 }.reversed().drop { $0 == 0x09 || $0 == 0x20 } + let trimmed = bytes.reversed().drop { $0 == 0x09 || $0 == 0x20 }.reversed().drop { + $0 == 0x09 || $0 == 0x20 + } return ISOLatin1String(unchecked: String(decoding: trimmed, as: UTF8.self)) } } @@ -242,11 +246,16 @@ extension HTTPField: Codable { let name = try container.decode(Name.self, forKey: .name) let value = try container.decode(String.self, forKey: .value) guard Self.isValidValue(value) else { - throw DecodingError.dataCorruptedError(forKey: .value, in: container, debugDescription: "HTTP field value \"\(value)\" contains invalid characters") + throw DecodingError.dataCorruptedError( + forKey: .value, + in: container, + debugDescription: "HTTP field value \"\(value)\" contains invalid characters" + ) } self.init(name: name, uncheckedValue: ISOLatin1String(unchecked: value)) if let indexingStrategyValue = try container.decodeIfPresent(UInt8.self, forKey: .indexingStrategy), - let indexingStrategy = DynamicTableIndexingStrategy(rawValue: indexingStrategyValue) { + let indexingStrategy = DynamicTableIndexingStrategy(rawValue: indexingStrategyValue) + { self.indexingStrategy = indexingStrategy } } @@ -254,15 +263,16 @@ extension HTTPField: Codable { extension HTTPField { static func isValidToken(_ token: some StringProtocol) -> Bool { - !token.isEmpty && token.utf8.allSatisfy { - switch $0 { - case 0x21, 0x23, 0x24, 0x25, 0x26, 0x27, 0x2A, 0x2B, 0x2D, 0x2E, 0x5E, 0x5F, 0x60, 0x7C, 0x7E: - return true - case 0x30 ... 0x39, 0x41 ... 0x5A, 0x61 ... 0x7A: // DIGHT, ALPHA - return true - default: - return false + !token.isEmpty + && token.utf8.allSatisfy { + switch $0 { + case 0x21, 0x23, 0x24, 0x25, 0x26, 0x27, 0x2A, 0x2B, 0x2D, 0x2E, 0x5E, 0x5F, 0x60, 0x7C, 0x7E: + return true + case 0x30...0x39, 0x41...0x5A, 0x61...0x7A: // DIGHT, ALPHA + return true + default: + return false + } } - } } } diff --git a/Sources/HTTPTypes/HTTPFieldName.swift b/Sources/HTTPTypes/HTTPFieldName.swift index e635e87..80b938e 100644 --- a/Sources/HTTPTypes/HTTPFieldName.swift +++ b/Sources/HTTPTypes/HTTPFieldName.swift @@ -66,16 +66,18 @@ extension HTTPField { } else { token = Substring(name) } - guard token.utf8.allSatisfy({ - switch $0 { - case 0x21, 0x23, 0x24, 0x25, 0x26, 0x27, 0x2A, 0x2B, 0x2D, 0x2E, 0x5E, 0x5F, 0x60, 0x7C, 0x7E: - return true - case 0x30 ... 0x39, 0x61 ... 0x7A: // DIGHT, ALPHA - return true - default: - return false - } - }) else { + guard + token.utf8.allSatisfy({ + switch $0 { + case 0x21, 0x23, 0x24, 0x25, 0x26, 0x27, 0x2A, 0x2B, 0x2D, 0x2E, 0x5E, 0x5F, 0x60, 0x7C, 0x7E: + return true + case 0x30...0x39, 0x61...0x7A: // DIGHT, ALPHA + return true + default: + return false + } + }) + else { return nil } self.rawName = name @@ -126,13 +128,20 @@ extension HTTPField.Name: Codable { let nameString = try container.decode(String.self) if nameString.hasPrefix(":") { guard nameString.lowercased() == nameString, - HTTPField.isValidToken(nameString.dropFirst()) else { - throw DecodingError.dataCorruptedError(in: container, debugDescription: "HTTP pseudo field name \"\(nameString)\" contains invalid characters") + HTTPField.isValidToken(nameString.dropFirst()) + else { + throw DecodingError.dataCorruptedError( + in: container, + debugDescription: "HTTP pseudo field name \"\(nameString)\" contains invalid characters" + ) } self.init(rawName: nameString, canonicalName: nameString) } else { guard let name = Self(nameString) else { - throw DecodingError.dataCorruptedError(in: container, debugDescription: "HTTP field name \"\(nameString)\" contains invalid characters") + throw DecodingError.dataCorruptedError( + in: container, + debugDescription: "HTTP field name \"\(nameString)\" contains invalid characters" + ) } self = name } @@ -170,42 +179,58 @@ extension HTTPField.Name { /// Access-Control-Allow-Credentials /// /// https://fetch.spec.whatwg.org/ - public static var accessControlAllowCredentials: Self { .init(rawName: "Access-Control-Allow-Credentials", canonicalName: "access-control-allow-credentials") } + public static var accessControlAllowCredentials: Self { + .init(rawName: "Access-Control-Allow-Credentials", canonicalName: "access-control-allow-credentials") + } /// Access-Control-Allow-Headers /// /// https://fetch.spec.whatwg.org/ - public static var accessControlAllowHeaders: Self { .init(rawName: "Access-Control-Allow-Headers", canonicalName: "access-control-allow-headers") } + public static var accessControlAllowHeaders: Self { + .init(rawName: "Access-Control-Allow-Headers", canonicalName: "access-control-allow-headers") + } /// Access-Control-Allow-Methods /// /// https://fetch.spec.whatwg.org/ - public static var accessControlAllowMethods: Self { .init(rawName: "Access-Control-Allow-Methods", canonicalName: "access-control-allow-methods") } + public static var accessControlAllowMethods: Self { + .init(rawName: "Access-Control-Allow-Methods", canonicalName: "access-control-allow-methods") + } /// Access-Control-Allow-Origin /// /// https://fetch.spec.whatwg.org/ - public static var accessControlAllowOrigin: Self { .init(rawName: "Access-Control-Allow-Origin", canonicalName: "access-control-allow-origin") } + public static var accessControlAllowOrigin: Self { + .init(rawName: "Access-Control-Allow-Origin", canonicalName: "access-control-allow-origin") + } /// Access-Control-Expose-Headers /// /// https://fetch.spec.whatwg.org/ - public static var accessControlExposeHeaders: Self { .init(rawName: "Access-Control-Expose-Headers", canonicalName: "access-control-expose-headers") } + public static var accessControlExposeHeaders: Self { + .init(rawName: "Access-Control-Expose-Headers", canonicalName: "access-control-expose-headers") + } /// Access-Control-Max-Age /// /// https://fetch.spec.whatwg.org/ - public static var accessControlMaxAge: Self { .init(rawName: "Access-Control-Max-Age", canonicalName: "access-control-max-age") } + public static var accessControlMaxAge: Self { + .init(rawName: "Access-Control-Max-Age", canonicalName: "access-control-max-age") + } /// Access-Control-Request-Headers /// /// https://fetch.spec.whatwg.org/ - public static var accessControlRequestHeaders: Self { .init(rawName: "Access-Control-Request-Headers", canonicalName: "access-control-request-headers") } + public static var accessControlRequestHeaders: Self { + .init(rawName: "Access-Control-Request-Headers", canonicalName: "access-control-request-headers") + } /// Access-Control-Request-Method /// /// https://fetch.spec.whatwg.org/ - public static var accessControlRequestMethod: Self { .init(rawName: "Access-Control-Request-Method", canonicalName: "access-control-request-method") } + public static var accessControlRequestMethod: Self { + .init(rawName: "Access-Control-Request-Method", canonicalName: "access-control-request-method") + } /// Age /// @@ -220,7 +245,9 @@ extension HTTPField.Name { /// Authentication-Info /// /// https://www.rfc-editor.org/rfc/rfc9110.html - public static var authenticationInfo: Self { .init(rawName: "Authentication-Info", canonicalName: "authentication-info") } + public static var authenticationInfo: Self { + .init(rawName: "Authentication-Info", canonicalName: "authentication-info") + } /// Authorization /// @@ -240,7 +267,9 @@ extension HTTPField.Name { /// Content-Disposition /// /// https://www.rfc-editor.org/rfc/rfc6266.html - public static var contentDisposition: Self { .init(rawName: "Content-Disposition", canonicalName: "content-disposition") } + public static var contentDisposition: Self { + .init(rawName: "Content-Disposition", canonicalName: "content-disposition") + } /// Content-Encoding /// @@ -270,12 +299,16 @@ extension HTTPField.Name { /// Content-Security-Policy /// /// https://www.w3.org/TR/CSP/ - public static var contentSecurityPolicy: Self { .init(rawName: "Content-Security-Policy", canonicalName: "content-security-policy") } + public static var contentSecurityPolicy: Self { + .init(rawName: "Content-Security-Policy", canonicalName: "content-security-policy") + } /// Content-Security-Policy-Report-Only /// /// https://www.w3.org/TR/CSP/ - public static var contentSecurityPolicyReportOnly: Self { .init(rawName: "Content-Security-Policy-Report-Only", canonicalName: "content-security-policy-report-only") } + public static var contentSecurityPolicyReportOnly: Self { + .init(rawName: "Content-Security-Policy-Report-Only", canonicalName: "content-security-policy-report-only") + } /// Content-Type /// @@ -290,7 +323,9 @@ extension HTTPField.Name { /// Cross-Origin-Resource-Policy /// /// https://fetch.spec.whatwg.org/ - public static var crossOriginResourcePolicy: Self { .init(rawName: "Cross-Origin-Resource-Policy", canonicalName: "cross-origin-resource-policy") } + public static var crossOriginResourcePolicy: Self { + .init(rawName: "Cross-Origin-Resource-Policy", canonicalName: "cross-origin-resource-policy") + } /// Date /// @@ -351,7 +386,9 @@ extension HTTPField.Name { /// If-Unmodified-Since /// /// https://www.rfc-editor.org/rfc/rfc9110.html - public static var ifUnmodifiedSince: Self { .init(rawName: "If-Unmodified-Since", canonicalName: "if-unmodified-since") } + public static var ifUnmodifiedSince: Self { + .init(rawName: "If-Unmodified-Since", canonicalName: "if-unmodified-since") + } /// Last-Modified /// @@ -381,17 +418,23 @@ extension HTTPField.Name { /// Proxy-Authenticate /// /// https://www.rfc-editor.org/rfc/rfc9110.html - public static var proxyAuthenticate: Self { .init(rawName: "Proxy-Authenticate", canonicalName: "proxy-authenticate") } + public static var proxyAuthenticate: Self { + .init(rawName: "Proxy-Authenticate", canonicalName: "proxy-authenticate") + } /// Proxy-Authentication-Info /// /// https://www.rfc-editor.org/rfc/rfc9110.html - public static var proxyAuthenticationInfo: Self { .init(rawName: "Proxy-Authentication-Info", canonicalName: "proxy-authentication-info") } + public static var proxyAuthenticationInfo: Self { + .init(rawName: "Proxy-Authentication-Info", canonicalName: "proxy-authentication-info") + } /// Proxy-Authorization /// /// https://www.rfc-editor.org/rfc/rfc9110.html - public static var proxyAuthorization: Self { .init(rawName: "Proxy-Authorization", canonicalName: "proxy-authorization") } + public static var proxyAuthorization: Self { + .init(rawName: "Proxy-Authorization", canonicalName: "proxy-authorization") + } /// Proxy-Status /// @@ -421,12 +464,16 @@ extension HTTPField.Name { /// Sec-WebSocket-Accept /// /// https://www.rfc-editor.org/rfc/rfc6455.html - public static var secWebSocketAccept: Self { .init(rawName: "Sec-WebSocket-Accept", canonicalName: "sec-websocket-accept") } + public static var secWebSocketAccept: Self { + .init(rawName: "Sec-WebSocket-Accept", canonicalName: "sec-websocket-accept") + } /// Sec-WebSocket-Extensions /// /// https://www.rfc-editor.org/rfc/rfc6455.html - public static var secWebSocketExtensions: Self { .init(rawName: "Sec-WebSocket-Extensions", canonicalName: "sec-websocket-extensions") } + public static var secWebSocketExtensions: Self { + .init(rawName: "Sec-WebSocket-Extensions", canonicalName: "sec-websocket-extensions") + } /// Sec-WebSocket-Key /// @@ -436,12 +483,16 @@ extension HTTPField.Name { /// Sec-WebSocket-Protocol /// /// https://www.rfc-editor.org/rfc/rfc6455.html - public static var secWebSocketProtocol: Self { .init(rawName: "Sec-WebSocket-Protocol", canonicalName: "sec-websocket-protocol") } + public static var secWebSocketProtocol: Self { + .init(rawName: "Sec-WebSocket-Protocol", canonicalName: "sec-websocket-protocol") + } /// Sec-WebSocket-Version /// /// https://www.rfc-editor.org/rfc/rfc6455.html - public static var secWebSocketVersion: Self { .init(rawName: "Sec-WebSocket-Version", canonicalName: "sec-websocket-version") } + public static var secWebSocketVersion: Self { + .init(rawName: "Sec-WebSocket-Version", canonicalName: "sec-websocket-version") + } /// Server /// @@ -456,7 +507,9 @@ extension HTTPField.Name { /// Strict-Transport-Security /// /// https://www.rfc-editor.org/rfc/rfc6797.html - public static var strictTransportSecurity: Self { .init(rawName: "Strict-Transport-Security", canonicalName: "strict-transport-security") } + public static var strictTransportSecurity: Self { + .init(rawName: "Strict-Transport-Security", canonicalName: "strict-transport-security") + } /// TE /// @@ -501,7 +554,9 @@ extension HTTPField.Name { /// X-Content-Type-Options /// /// https://fetch.spec.whatwg.org/ - public static var xContentTypeOptions: Self { .init(rawName: "X-Content-Type-Options", canonicalName: "x-content-type-options") } + public static var xContentTypeOptions: Self { + .init(rawName: "X-Content-Type-Options", canonicalName: "x-content-type-options") + } // Deprecated /// P3P @@ -522,15 +577,21 @@ extension HTTPField.Name { /// Proxy-Connection static var proxyConnection: Self { .init(rawName: "Proxy-Connection", canonicalName: "proxy-connection") } /// Upgrade-Insecure-Requests - static var upgradeInsecureRequests: Self { .init(rawName: "Upgrade-Insecure-Requests", canonicalName: "upgrade-insecure-requests") } + static var upgradeInsecureRequests: Self { + .init(rawName: "Upgrade-Insecure-Requests", canonicalName: "upgrade-insecure-requests") + } /// Datagram-Flow-Id static var datagramFlowId: Self { .init(rawName: "Datagram-Flow-Id", canonicalName: "datagram-flow-id") } /// Capsule-Protocol static var capsuleProtocol: Self { .init(rawName: "Capsule-Protocol", canonicalName: "capsule-protocol") } /// Server-Connection-Id - static var serverConnectionId: Self { .init(rawName: "Server-Connection-Id", canonicalName: "server-connection-id") } + static var serverConnectionId: Self { + .init(rawName: "Server-Connection-Id", canonicalName: "server-connection-id") + } /// Client-Connection-Id - static var clientConnectionId: Self { .init(rawName: "Client-Connection-Id", canonicalName: "client-connection-id") } + static var clientConnectionId: Self { + .init(rawName: "Client-Connection-Id", canonicalName: "client-connection-id") + } /// Sec-CH-Background static var secCHBackground: Self { .init(rawName: "Sec-CH-Background", canonicalName: "sec-ch-background") } /// Sec-CH-Geohash @@ -538,7 +599,9 @@ extension HTTPField.Name { /// Client-Geohash static var clientGeohash: Self { .init(rawName: "Client-Geohash", canonicalName: "client-geohash") } /// Proxy-QUIC-Forwarding - static var proxyQUICForwarding: Self { .init(rawName: "Proxy-QUIC-Forwarding", canonicalName: "proxy-quic-forwarding") } + static var proxyQUICForwarding: Self { + .init(rawName: "Proxy-QUIC-Forwarding", canonicalName: "proxy-quic-forwarding") + } /// Proxy-Config-Epoch static var proxyConfigEpoch: Self { .init(rawName: "Proxy-Config-Epoch", canonicalName: "proxy-config-epoch") } /// Connect-UDP-Bind diff --git a/Sources/HTTPTypes/HTTPFields.swift b/Sources/HTTPTypes/HTTPFields.swift index d188df4..c5319b4 100644 --- a/Sources/HTTPTypes/HTTPFields.swift +++ b/Sources/HTTPTypes/HTTPFields.swift @@ -133,10 +133,14 @@ public struct HTTPFields: Sendable, Hashable { set { if let newValue { if #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *), - name == .cookie { - self.setFields(newValue.split(separator: "; ", omittingEmptySubsequences: false).lazy.map { - HTTPField(name: name, value: String($0)) - }, for: name) + name == .cookie + { + self.setFields( + newValue.split(separator: "; ", omittingEmptySubsequences: false).lazy.map { + HTTPField(name: name, value: String($0)) + }, + for: name + ) } else { self.setFields(CollectionOfOne(HTTPField(name: name, value: newValue)), for: name) } @@ -278,7 +282,8 @@ extension HTTPFields: RangeReplaceableCollection, RandomAccessCollection, Mutabl } } - public mutating func replaceSubrange(_ subrange: Range, with newElements: C) where C: Collection, Element == C.Element { + public mutating func replaceSubrange(_ subrange: Range, with newElements: C) + where C: Collection, Element == C.Element { if !isKnownUniquelyReferenced(&self._storage) { self._storage = self._storage.copy() } @@ -289,10 +294,13 @@ extension HTTPFields: RangeReplaceableCollection, RandomAccessCollection, Mutabl } } else { self._storage.index = nil - self._storage.fields.replaceSubrange(subrange, with: newElements.lazy.map { field in - precondition(!field.name.isPseudo, "Pseudo header field \"\(field.name)\" disallowed") - return (field, 0) - }) + self._storage.fields.replaceSubrange( + subrange, + with: newElements.lazy.map { field in + precondition(!field.name.isPseudo, "Pseudo header field \"\(field.name)\" disallowed") + return (field, 0) + } + ) precondition(self.count < UInt16.max, "Too many fields") } } @@ -326,7 +334,10 @@ extension HTTPFields: Codable { while !container.isAtEnd { let field = try container.decode(HTTPField.self) guard !field.name.isPseudo else { - throw DecodingError.dataCorruptedError(in: container, debugDescription: "Pseudo header field \"\(field)\" disallowed") + throw DecodingError.dataCorruptedError( + in: container, + debugDescription: "Pseudo header field \"\(field)\" disallowed" + ) } self.append(field) } diff --git a/Sources/HTTPTypes/HTTPParsedFields.swift b/Sources/HTTPTypes/HTTPParsedFields.swift index d9e56cc..33ff1c0 100644 --- a/Sources/HTTPTypes/HTTPParsedFields.swift +++ b/Sources/HTTPTypes/HTTPParsedFields.swift @@ -111,9 +111,18 @@ struct HTTPParsedFields { throw ParsingError.requestWithResponsePseudo } try self.validateFields() - var request = HTTPRequest(method: requestMethod, scheme: self.scheme, authority: self.authority, path: self.path, headerFields: self.fields) + var request = HTTPRequest( + method: requestMethod, + scheme: self.scheme, + authority: self.authority, + path: self.path, + headerFields: self.fields + ) if let extendedConnectProtocol = self.extendedConnectProtocol { - request.pseudoHeaderFields.extendedConnectProtocol = HTTPField(name: .protocol, uncheckedValue: extendedConnectProtocol) + request.pseudoHeaderFields.extendedConnectProtocol = HTTPField( + name: .protocol, + uncheckedValue: extendedConnectProtocol + ) } return request } @@ -124,7 +133,9 @@ struct HTTPParsedFields { guard let statusString = self.status?._storage else { throw ParsingError.responseWithoutStatus } - if self.method != nil || self.scheme != nil || self.authority != nil || self.path != nil || self.extendedConnectProtocol != nil { + if self.method != nil || self.scheme != nil || self.authority != nil || self.path != nil + || self.extendedConnectProtocol != nil + { throw ParsingError.responseWithRequestPseudo } if !HTTPResponse.Status.isValidStatus(statusString) { @@ -137,7 +148,9 @@ struct HTTPParsedFields { var trailerFields: HTTPFields { get throws { - if self.method != nil || self.scheme != nil || self.authority != nil || self.path != nil || self.extendedConnectProtocol != nil || self.status != nil { + if self.method != nil || self.scheme != nil || self.authority != nil || self.path != nil + || self.extendedConnectProtocol != nil || self.status != nil + { throw ParsingError.trailerFieldsWithPseudo } try self.validateFields() @@ -147,12 +160,23 @@ struct HTTPParsedFields { } extension HTTPRequest { - fileprivate init(method: Method, scheme: ISOLatin1String?, authority: ISOLatin1String?, path: ISOLatin1String?, headerFields: HTTPFields) { + fileprivate init( + method: Method, + scheme: ISOLatin1String?, + authority: ISOLatin1String?, + path: ISOLatin1String?, + headerFields: HTTPFields + ) { let methodField = HTTPField(name: .method, uncheckedValue: ISOLatin1String(unchecked: method.rawValue)) let schemeField = scheme.map { HTTPField(name: .scheme, uncheckedValue: $0) } let authorityField = authority.map { HTTPField(name: .authority, uncheckedValue: $0) } let pathField = path.map { HTTPField(name: .path, uncheckedValue: $0) } - self.pseudoHeaderFields = .init(method: methodField, scheme: schemeField, authority: authorityField, path: pathField) + self.pseudoHeaderFields = .init( + method: methodField, + scheme: schemeField, + authority: authorityField, + path: pathField + ) self.headerFields = headerFields } } diff --git a/Sources/HTTPTypes/HTTPRequest.swift b/Sources/HTTPTypes/HTTPRequest.swift index 269ad6e..9361357 100644 --- a/Sources/HTTPTypes/HTTPRequest.swift +++ b/Sources/HTTPTypes/HTTPRequest.swift @@ -213,7 +213,12 @@ public struct HTTPRequest: Sendable, Hashable { let schemeField = scheme.map { HTTPField(name: .scheme, value: $0) } let authorityField = authority.map { HTTPField(name: .authority, value: $0) } let pathField = path.map { HTTPField(name: .path, value: $0) } - self.pseudoHeaderFields = .init(method: methodField, scheme: schemeField, authority: authorityField, path: pathField) + self.pseudoHeaderFields = .init( + method: methodField, + scheme: schemeField, + authority: authorityField, + path: pathField + ) self.headerFields = headerFields } } @@ -254,40 +259,64 @@ extension HTTPRequest.PseudoHeaderFields: Codable { switch field.name { case .method: guard method == nil else { - throw DecodingError.dataCorruptedError(in: container, debugDescription: "Multiple \":method\" pseudo header fields") + throw DecodingError.dataCorruptedError( + in: container, + debugDescription: "Multiple \":method\" pseudo header fields" + ) } method = field case .scheme: guard scheme == nil else { - throw DecodingError.dataCorruptedError(in: container, debugDescription: "Multiple \":scheme\" pseudo header fields") + throw DecodingError.dataCorruptedError( + in: container, + debugDescription: "Multiple \":scheme\" pseudo header fields" + ) } scheme = field case .authority: guard authority == nil else { - throw DecodingError.dataCorruptedError(in: container, debugDescription: "Multiple \":authority\" pseudo header fields") + throw DecodingError.dataCorruptedError( + in: container, + debugDescription: "Multiple \":authority\" pseudo header fields" + ) } authority = field case .path: guard path == nil else { - throw DecodingError.dataCorruptedError(in: container, debugDescription: "Multiple \":path\" pseudo header fields") + throw DecodingError.dataCorruptedError( + in: container, + debugDescription: "Multiple \":path\" pseudo header fields" + ) } path = field case .protocol: guard extendedConnectProtocol == nil else { - throw DecodingError.dataCorruptedError(in: container, debugDescription: "Multiple \":protocol\" pseudo header fields") + throw DecodingError.dataCorruptedError( + in: container, + debugDescription: "Multiple \":protocol\" pseudo header fields" + ) } extendedConnectProtocol = field default: guard field.name.rawName.hasPrefix(":") else { - throw DecodingError.dataCorruptedError(in: container, debugDescription: "\"\(field)\" is not a pseudo header field") + throw DecodingError.dataCorruptedError( + in: container, + debugDescription: "\"\(field)\" is not a pseudo header field" + ) } } } guard let method else { - throw DecodingError.dataCorruptedError(in: container, debugDescription: "\":method\" pseudo header field is missing") + throw DecodingError.dataCorruptedError( + in: container, + debugDescription: "\":method\" pseudo header field is missing" + ) } guard HTTPField.isValidToken(method.rawValue._storage) else { - throw DecodingError.dataCorruptedError(in: container, debugDescription: "\"\(method.rawValue._storage)\" is not a valid method") + throw DecodingError.dataCorruptedError( + in: container, + debugDescription: "\"\(method.rawValue._storage)\" is not a valid method" + ) } self.init( method: method, diff --git a/Sources/HTTPTypes/HTTPResponse.swift b/Sources/HTTPTypes/HTTPResponse.swift index 863bdae..975dc0f 100644 --- a/Sources/HTTPTypes/HTTPResponse.swift +++ b/Sources/HTTPTypes/HTTPResponse.swift @@ -33,7 +33,7 @@ public struct HTTPResponse: Sendable, Hashable { /// characters not representable in ISO Latin 1 encoding, are converted /// into space characters. public init(code: Int, reasonPhrase: String = "") { - precondition((0 ... 999).contains(code), "Invalid status code") + precondition((0...999).contains(code), "Invalid status code") self.code = code self.reasonPhrase = Self.legalizingReasonPhrase(reasonPhrase) } @@ -46,7 +46,7 @@ public struct HTTPResponse: Sendable, Hashable { /// Create a custom status from an integer literal. /// - Parameter value: The status code. public init(integerLiteral value: Int) { - precondition((0 ... 999).contains(value), "Invalid status code") + precondition((0...999).contains(value), "Invalid status code") self.code = value self.reasonPhrase = "" } @@ -70,15 +70,15 @@ public struct HTTPResponse: Sendable, Hashable { /// The kind of the status code. public var kind: Kind { switch self.code { - case 100 ... 199: + case 100...199: return .informational - case 200 ... 299: + case 200...299: return .successful - case 300 ... 399: + case 300...399: return .redirection - case 400 ... 499: + case 400...499: return .clientError - case 500 ... 599: + case 500...599: return .serverError default: return .invalid @@ -115,7 +115,7 @@ public struct HTTPResponse: Sendable, Hashable { } static func isValidStatus(_ status: String) -> Bool { - status.count == 3 && status.utf8.allSatisfy { (0x30 ... 0x39).contains($0) } + status.count == 3 && status.utf8.allSatisfy { (0x30...0x39).contains($0) } } static func isValidReasonPhrase(_ reasonPhrase: String) -> Bool { @@ -123,7 +123,7 @@ public struct HTTPResponse: Sendable, Hashable { switch $0 { case 0x09, 0x20: return true - case 0x21 ... 0x7E, 0x80 ... 0xFF: + case 0x21...0x7E, 0x80...0xFF: return true default: return false @@ -139,7 +139,7 @@ public struct HTTPResponse: Sendable, Hashable { switch scala.value { case 0x09, 0x20: return scala - case 0x21 ... 0x7E, 0x80 ... 0xFF: + case 0x21...0x7E, 0x80...0xFF: return scala default: return " " @@ -159,9 +159,9 @@ public struct HTTPResponse: Sendable, Hashable { public var status: Status { get { var codeIterator = self.pseudoHeaderFields.status.rawValue._storage.utf8.makeIterator() - let code = Int(codeIterator.next()! - 48) * 100 + - Int(codeIterator.next()! - 48) * 10 + - Int(codeIterator.next()! - 48) + let code = + Int(codeIterator.next()! - 48) * 100 + Int(codeIterator.next()! - 48) * 10 + + Int(codeIterator.next()! - 48) return Status(uncheckedCode: code, reasonPhrase: self.reasonPhrase) } set { @@ -232,20 +232,32 @@ extension HTTPResponse.PseudoHeaderFields: Codable { switch field.name { case .status: guard status == nil else { - throw DecodingError.dataCorruptedError(in: container, debugDescription: "Multiple \":status\" pseudo header fields") + throw DecodingError.dataCorruptedError( + in: container, + debugDescription: "Multiple \":status\" pseudo header fields" + ) } status = field default: guard field.name.rawName.hasPrefix(":") else { - throw DecodingError.dataCorruptedError(in: container, debugDescription: "\"\(field)\" is not a pseudo header field") + throw DecodingError.dataCorruptedError( + in: container, + debugDescription: "\"\(field)\" is not a pseudo header field" + ) } } } guard let status else { - throw DecodingError.dataCorruptedError(in: container, debugDescription: "\":status\" pseudo header field is missing") + throw DecodingError.dataCorruptedError( + in: container, + debugDescription: "\":status\" pseudo header field is missing" + ) } guard HTTPResponse.Status.isValidStatus(status.rawValue._storage) else { - throw DecodingError.dataCorruptedError(in: container, debugDescription: "\"\(status.rawValue._storage)\" is not a valid status code") + throw DecodingError.dataCorruptedError( + in: container, + debugDescription: "\"\(status.rawValue._storage)\" is not a valid status code" + ) } self.init(status: status) } @@ -319,7 +331,9 @@ extension HTTPResponse.Status { /// 203 Non-Authoritative Information /// /// https://www.rfc-editor.org/rfc/rfc9110.html - public static var nonAuthoritativeInformation: Self { .init(uncheckedCode: 203, reasonPhrase: "Non-Authoritative Information") } + public static var nonAuthoritativeInformation: Self { + .init(uncheckedCode: 203, reasonPhrase: "Non-Authoritative Information") + } /// 204 No Content /// @@ -408,7 +422,9 @@ extension HTTPResponse.Status { /// 407 Proxy Authentication Required /// /// https://www.rfc-editor.org/rfc/rfc9110.html - public static var proxyAuthenticationRequired: Self { .init(uncheckedCode: 407, reasonPhrase: "Proxy Authentication Required") } + public static var proxyAuthenticationRequired: Self { + .init(uncheckedCode: 407, reasonPhrase: "Proxy Authentication Required") + } /// 408 Request Timeout /// @@ -491,12 +507,16 @@ extension HTTPResponse.Status { /// 431 Request Header Fields Too Large /// /// https://www.rfc-editor.org/rfc/rfc6585.html - public static var requestHeaderFieldsTooLarge: Self { .init(uncheckedCode: 431, reasonPhrase: "Request Header Fields Too Large") } + public static var requestHeaderFieldsTooLarge: Self { + .init(uncheckedCode: 431, reasonPhrase: "Request Header Fields Too Large") + } /// 451 Unavailable For Legal Reasons /// /// https://www.rfc-editor.org/rfc/rfc7725.html - public static var unavailableForLegalReasons: Self { .init(uncheckedCode: 451, reasonPhrase: "Unavailable For Legal Reasons") } + public static var unavailableForLegalReasons: Self { + .init(uncheckedCode: 451, reasonPhrase: "Unavailable For Legal Reasons") + } // MARK: 5xx @@ -528,10 +548,14 @@ extension HTTPResponse.Status { /// 505 HTTP Version Not Supported /// /// https://www.rfc-editor.org/rfc/rfc9110.html - public static var httpVersionNotSupported: Self { .init(uncheckedCode: 505, reasonPhrase: "HTTP Version Not Supported") } + public static var httpVersionNotSupported: Self { + .init(uncheckedCode: 505, reasonPhrase: "HTTP Version Not Supported") + } /// 511 Network Authentication Required /// /// https://www.rfc-editor.org/rfc/rfc6585.html - public static var networkAuthenticationRequired: Self { .init(uncheckedCode: 511, reasonPhrase: "Network Authentication Required") } + public static var networkAuthenticationRequired: Self { + .init(uncheckedCode: 511, reasonPhrase: "Network Authentication Required") + } } diff --git a/Sources/HTTPTypes/ISOLatin1String.swift b/Sources/HTTPTypes/ISOLatin1String.swift index 696f6c2..a5c08f7 100644 --- a/Sources/HTTPTypes/ISOLatin1String.swift +++ b/Sources/HTTPTypes/ISOLatin1String.swift @@ -28,7 +28,9 @@ struct ISOLatin1String: Sendable, Hashable { return string } - private func withISOLatin1BytesSlowPath(_ body: (UnsafeBufferPointer) throws -> Result) rethrows -> Result { + private func withISOLatin1BytesSlowPath( + _ body: (UnsafeBufferPointer) throws -> Result + ) rethrows -> Result { try withUnsafeTemporaryAllocation(of: UInt8.self, capacity: self._storage.unicodeScalars.count) { buffer in for (index, scalar) in self._storage.unicodeScalars.enumerated() { assert(scalar.value <= UInt8.max) diff --git a/Sources/HTTPTypesFoundation/HTTPRequest+URL.swift b/Sources/HTTPTypesFoundation/HTTPRequest+URL.swift index e8f3b88..66562f5 100644 --- a/Sources/HTTPTypesFoundation/HTTPRequest+URL.swift +++ b/Sources/HTTPTypesFoundation/HTTPRequest+URL.swift @@ -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 { - UnsafeMutableBufferPointer(rebasing: buffer[range.location ..< range.location + range.length]) + UnsafeMutableBufferPointer(rebasing: buffer[range.location.. UInt8.max { buffer[index] = 0x20 diff --git a/Sources/HTTPTypesFoundation/URLRequest+HTTPTypes.swift b/Sources/HTTPTypesFoundation/URLRequest+HTTPTypes.swift index 20152d4..624f8a3 100644 --- a/Sources/HTTPTypesFoundation/URLRequest+HTTPTypes.swift +++ b/Sources/HTTPTypesFoundation/URLRequest+HTTPTypes.swift @@ -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 } diff --git a/Sources/HTTPTypesFoundation/URLResponse+HTTPTypes.swift b/Sources/HTTPTypesFoundation/URLResponse+HTTPTypes.swift index dfcc839..7a3e371 100644 --- a/Sources/HTTPTypesFoundation/URLResponse+HTTPTypes.swift +++ b/Sources/HTTPTypesFoundation/URLResponse+HTTPTypes.swift @@ -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)) diff --git a/Sources/HTTPTypesFoundation/URLSession+HTTPTypes.swift b/Sources/HTTPTypesFoundation/URLSession+HTTPTypes.swift index 1cdb689..cdf2de6 100644 --- a/Sources/HTTPTypesFoundation/URLSession+HTTPTypes.swift +++ b/Sources/HTTPTypesFoundation/URLSession+HTTPTypes.swift @@ -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 } diff --git a/Tests/HTTPTypesFoundationTests/HTTPTypesFoundationTests.swift b/Tests/HTTPTypesFoundationTests/HTTPTypesFoundationTests.swift index 42f4a24..51dd654 100644 --- a/Tests/HTTPTypesFoundationTests/HTTPTypesFoundationTests.swift +++ b/Tests/HTTPTypesFoundationTests/HTTPTypesFoundationTests.swift @@ -15,6 +15,7 @@ import HTTPTypes import HTTPTypesFoundation import XCTest + #if canImport(FoundationNetworking) import FoundationNetworking #endif @@ -54,7 +55,10 @@ final class HTTPTypesFoundationTests: XCTestCase { func testRequestToFoundation() throws { let request = HTTPRequest( - method: .get, scheme: "https", authority: "www.example.com", path: "/", + method: .get, + scheme: "https", + authority: "www.example.com", + path: "/", headerFields: [ .accept: "*/*", .acceptEncoding: "gzip", @@ -88,20 +92,24 @@ final class HTTPTypesFoundationTests: XCTestCase { let response = HTTPResponse( status: .ok, headerFields: [ - .server: "HTTPServer/1.0", + .server: "HTTPServer/1.0" ] ) - let urlResponse = try XCTUnwrap(HTTPURLResponse(httpResponse: response, url: URL(string: "https://www.example.com/")!)) + let urlResponse = try XCTUnwrap( + HTTPURLResponse(httpResponse: response, url: URL(string: "https://www.example.com/")!) + ) XCTAssertEqual(urlResponse.statusCode, 200) XCTAssertEqual(urlResponse.value(forHTTPHeaderField: "Server"), "HTTPServer/1.0") } func testResponseFromFoundation() throws { let urlResponse = HTTPURLResponse( - url: URL(string: "https://www.example.com/")!, statusCode: 204, httpVersion: nil, + url: URL(string: "https://www.example.com/")!, + statusCode: 204, + httpVersion: nil, headerFields: [ - "X-Emoji": "😀", + "X-Emoji": "😀" ] )! diff --git a/Tests/HTTPTypesTests/HTTPTypesTests.swift b/Tests/HTTPTypesTests/HTTPTypesTests.swift index cb2852d..a199d9c 100644 --- a/Tests/HTTPTypesTests/HTTPTypesTests.swift +++ b/Tests/HTTPTypesTests/HTTPTypesTests.swift @@ -44,9 +44,14 @@ final class HTTPTypesTests: XCTestCase { func testRequest() { var request1 = HTTPRequest(method: .get, scheme: "https", authority: "www.example.com", path: "/") request1.headerFields = [ - .acceptLanguage: "en", + .acceptLanguage: "en" ] - var request2 = HTTPRequest(method: HTTPRequest.Method("GET")!, scheme: "https", authority: "www.example.com", path: "/") + var request2 = HTTPRequest( + method: HTTPRequest.Method("GET")!, + scheme: "https", + authority: "www.example.com", + path: "/" + ) request2.headerFields.append(HTTPField(name: .acceptLanguageUpper, value: "en")) XCTAssertEqual(request2.method, .get) @@ -145,49 +150,64 @@ final class HTTPTypesTests: XCTestCase { } func testRequestCoding() throws { - let request = HTTPRequest(method: .put, scheme: "https", authority: "www.example.com", path: "/upload", headerFields: [ - .acceptEncoding: "br", - .acceptEncoding: "gzip", - .contentLength: "1024", - ]) + let request = HTTPRequest( + method: .put, + scheme: "https", + authority: "www.example.com", + path: "/upload", + headerFields: [ + .acceptEncoding: "br", + .acceptEncoding: "gzip", + .contentLength: "1024", + ] + ) let encoded = try JSONEncoder().encode(request) let json = try JSONSerialization.jsonObject(with: encoded) - XCTAssertEqual(json as? NSDictionary, [ - "pseudoHeaderFields": [ - ["name": ":method", "value": "PUT"], - ["name": ":scheme", "value": "https"], - ["name": ":authority", "value": "www.example.com"], - ["name": ":path", "value": "/upload"], - ], - "headerFields": [ - ["name": "Accept-Encoding", "value": "br"], - ["name": "Accept-Encoding", "value": "gzip"], - ["name": "Content-Length", "value": "1024"], - ], - ]) + XCTAssertEqual( + json as? NSDictionary, + [ + "pseudoHeaderFields": [ + ["name": ":method", "value": "PUT"], + ["name": ":scheme", "value": "https"], + ["name": ":authority", "value": "www.example.com"], + ["name": ":path", "value": "/upload"], + ], + "headerFields": [ + ["name": "Accept-Encoding", "value": "br"], + ["name": "Accept-Encoding", "value": "gzip"], + ["name": "Content-Length", "value": "1024"], + ], + ] + ) let decoded = try JSONDecoder().decode(HTTPRequest.self, from: encoded) XCTAssertEqual(request, decoded) } func testResponseCoding() throws { - var response = HTTPResponse(status: .noContent, headerFields: [ - .server: "HTTPServer/1.0", - ]) + var response = HTTPResponse( + status: .noContent, + headerFields: [ + .server: "HTTPServer/1.0" + ] + ) response.headerFields[0].indexingStrategy = .prefer let encoded = try JSONEncoder().encode(response) let json = try JSONSerialization.jsonObject(with: encoded) - XCTAssertEqual(json as? NSDictionary, [ - "pseudoHeaderFields": [ - ["name": ":status", "value": "204"], - ], - "reasonPhrase": "No Content", - "headerFields": [ - ["name": "Server", "value": "HTTPServer/1.0", "indexingStrategy": 1], - ], - ]) + XCTAssertEqual( + json as? NSDictionary, + [ + "pseudoHeaderFields": [ + ["name": ":status", "value": "204"] + ], + "reasonPhrase": "No Content", + "headerFields": [ + ["name": "Server", "value": "HTTPServer/1.0", "indexingStrategy": 1] + ], + ] + ) let decoded = try JSONDecoder().decode(HTTPResponse.self, from: encoded) XCTAssertEqual(response, decoded) diff --git a/scripts/preview_docc.sh b/scripts/preview_docc.sh index 8ac76bd..c842bad 100755 --- a/scripts/preview_docc.sh +++ b/scripts/preview_docc.sh @@ -13,4 +13,4 @@ ## ##===----------------------------------------------------------------------===## -swift package --disable-sandbox preview-documentation --target $1 +swift package --disable-sandbox preview-documentation --target "$1" From 310e8eaf924f4e9852c95eec9c5d383ab8fc5ad1 Mon Sep 17 00:00:00 2001 From: Franz Busch Date: Thu, 24 Oct 2024 12:52:32 +0200 Subject: [PATCH 2/5] Change compiler checks --- Sources/HTTPTypesFoundation/URLSession+HTTPTypes.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/HTTPTypesFoundation/URLSession+HTTPTypes.swift b/Sources/HTTPTypesFoundation/URLSession+HTTPTypes.swift index cdf2de6..8bcc343 100644 --- a/Sources/HTTPTypesFoundation/URLSession+HTTPTypes.swift +++ b/Sources/HTTPTypesFoundation/URLSession+HTTPTypes.swift @@ -45,7 +45,7 @@ private enum HTTPTypeConversionError: Error { #endif -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || compiler(>=6) || (compiler(>=6) && os(visionOS)) +#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || compiler(>=6) @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) extension URLSession { @@ -129,7 +129,7 @@ extension URLSession { return (location, response) } - #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || (compiler(>=6) && os(visionOS)) + #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || compiler(>=6) /// Returns a byte stream that conforms to AsyncSequence protocol. /// /// - Parameter request: The `HTTPRequest` for which to load data. From 700f1999c0e56c6aacf629341c865a54560d5a1b Mon Sep 17 00:00:00 2001 From: Franz Busch Date: Thu, 24 Oct 2024 22:31:48 +0200 Subject: [PATCH 3/5] Enable Windows --- .github/workflows/main.yml | 6 ++++++ .github/workflows/pull_request.yml | 6 ++++++ .github/workflows/scheduled.yml | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a16ffc8..f28f262 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,6 +14,12 @@ jobs: linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error" + windows_6_0_enabled: true + windows_nightly_6_0_enabled: true + windows_nightly_main_enabled: true + windows_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + windows_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable benchmarks: name: Benchmarks diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 6ed21cc..496121a 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -20,6 +20,12 @@ jobs: linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error" + windows_6_0_enabled: true + windows_nightly_6_0_enabled: true + windows_nightly_main_enabled: true + windows_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + windows_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" benchmarks: name: Benchmarks diff --git a/.github/workflows/scheduled.yml b/.github/workflows/scheduled.yml index b9db48f..f074166 100644 --- a/.github/workflows/scheduled.yml +++ b/.github/workflows/scheduled.yml @@ -14,6 +14,12 @@ jobs: linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error" + windows_6_0_enabled: true + windows_nightly_6_0_enabled: true + windows_nightly_main_enabled: true + windows_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + windows_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable benchmarks: name: Benchmarks From 95045b96be9a3ddffa452959f0ed1ed4340a7439 Mon Sep 17 00:00:00 2001 From: Franz Busch Date: Fri, 25 Oct 2024 10:51:29 +0200 Subject: [PATCH 4/5] Revert "Change compiler checks" This reverts commit 310e8eaf924f4e9852c95eec9c5d383ab8fc5ad1. --- Sources/HTTPTypesFoundation/URLSession+HTTPTypes.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/HTTPTypesFoundation/URLSession+HTTPTypes.swift b/Sources/HTTPTypesFoundation/URLSession+HTTPTypes.swift index 8bcc343..cdf2de6 100644 --- a/Sources/HTTPTypesFoundation/URLSession+HTTPTypes.swift +++ b/Sources/HTTPTypesFoundation/URLSession+HTTPTypes.swift @@ -45,7 +45,7 @@ private enum HTTPTypeConversionError: Error { #endif -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || 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 { @@ -129,7 +129,7 @@ extension URLSession { return (location, response) } - #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || compiler(>=6) + #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. From 5eeef940dd79964aacfd194ee64136375cba7701 Mon Sep 17 00:00:00 2001 From: Franz Busch Date: Mon, 28 Oct 2024 11:13:19 +0100 Subject: [PATCH 5/5] Fix checks --- .github/workflows/main.yml | 4 ++- .github/workflows/scheduled.yml | 32 ------------------- .../HTTPFieldsBenchmarks/Benchmarks.swift | 2 +- ...TPFields.init(dictionaryLiteral).p90.json} | 0 ...TPFields.init(dictionaryLiteral).p90.json} | 0 ...TPFields.init(dictionaryLiteral).p90.json} | 0 ...TPFields.init(dictionaryLiteral).p90.json} | 0 ...TPFields.init(dictionaryLiteral).p90.json} | 0 Sources/HTTPTypes/NIOLock.swift | 13 ++++++++ 9 files changed, 17 insertions(+), 34 deletions(-) delete mode 100644 .github/workflows/scheduled.yml rename Benchmarks/Thresholds/5.10/{Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json => Benchmarks.HTTPFields.init(dictionaryLiteral).p90.json} (100%) rename Benchmarks/Thresholds/5.9/{Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json => Benchmarks.HTTPFields.init(dictionaryLiteral).p90.json} (100%) rename Benchmarks/Thresholds/6.0/{Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json => Benchmarks.HTTPFields.init(dictionaryLiteral).p90.json} (100%) rename Benchmarks/Thresholds/nightly-6.0/{Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json => Benchmarks.HTTPFields.init(dictionaryLiteral).p90.json} (100%) rename Benchmarks/Thresholds/nightly-main/{Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json => Benchmarks.HTTPFields.init(dictionaryLiteral).p90.json} (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f28f262..9f0282f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,6 +3,8 @@ name: Main on: push: branches: [main] + schedule: + - cron: "0 8,20 * * *" jobs: unit-tests: @@ -19,7 +21,7 @@ jobs: windows_nightly_main_enabled: true windows_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" windows_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" - windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable + windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" benchmarks: name: Benchmarks diff --git a/.github/workflows/scheduled.yml b/.github/workflows/scheduled.yml deleted file mode 100644 index f074166..0000000 --- a/.github/workflows/scheduled.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Scheduled - -on: - schedule: - - cron: "0 8,20 * * *" - -jobs: - unit-tests: - name: Unit tests - uses: apple/swift-nio/.github/workflows/unit_tests.yml@main - with: - linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" - linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" - linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" - linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error" - linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error" - windows_6_0_enabled: true - windows_nightly_6_0_enabled: true - windows_nightly_main_enabled: true - windows_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" - windows_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" - windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable - - benchmarks: - name: Benchmarks - uses: apple/swift-nio/.github/workflows/benchmarks.yml@main - with: - benchmark_package_path: "Benchmarks" - - cxx-interop: - name: Cxx interop - uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main diff --git a/Benchmarks/Benchmarks/HTTPFieldsBenchmarks/Benchmarks.swift b/Benchmarks/Benchmarks/HTTPFieldsBenchmarks/Benchmarks.swift index 8fb9e34..b882c7c 100644 --- a/Benchmarks/Benchmarks/HTTPFieldsBenchmarks/Benchmarks.swift +++ b/Benchmarks/Benchmarks/HTTPFieldsBenchmarks/Benchmarks.swift @@ -21,7 +21,7 @@ let benchmarks = { ] Benchmark( - "HTTPFields.init(dictionaryLiteral:)", + "HTTPFields.init(dictionaryLiteral)", configuration: .init( metrics: defaultMetrics, scalingFactor: .kilo, diff --git a/Benchmarks/Thresholds/5.10/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json b/Benchmarks/Thresholds/5.10/Benchmarks.HTTPFields.init(dictionaryLiteral).p90.json similarity index 100% rename from Benchmarks/Thresholds/5.10/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json rename to Benchmarks/Thresholds/5.10/Benchmarks.HTTPFields.init(dictionaryLiteral).p90.json diff --git a/Benchmarks/Thresholds/5.9/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json b/Benchmarks/Thresholds/5.9/Benchmarks.HTTPFields.init(dictionaryLiteral).p90.json similarity index 100% rename from Benchmarks/Thresholds/5.9/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json rename to Benchmarks/Thresholds/5.9/Benchmarks.HTTPFields.init(dictionaryLiteral).p90.json diff --git a/Benchmarks/Thresholds/6.0/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json b/Benchmarks/Thresholds/6.0/Benchmarks.HTTPFields.init(dictionaryLiteral).p90.json similarity index 100% rename from Benchmarks/Thresholds/6.0/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json rename to Benchmarks/Thresholds/6.0/Benchmarks.HTTPFields.init(dictionaryLiteral).p90.json diff --git a/Benchmarks/Thresholds/nightly-6.0/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json b/Benchmarks/Thresholds/nightly-6.0/Benchmarks.HTTPFields.init(dictionaryLiteral).p90.json similarity index 100% rename from Benchmarks/Thresholds/nightly-6.0/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json rename to Benchmarks/Thresholds/nightly-6.0/Benchmarks.HTTPFields.init(dictionaryLiteral).p90.json diff --git a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.init(dictionaryLiteral).p90.json similarity index 100% rename from Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.init(dictionaryLiteral:).p90.json rename to Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.init(dictionaryLiteral).p90.json diff --git a/Sources/HTTPTypes/NIOLock.swift b/Sources/HTTPTypes/NIOLock.swift index b670565..b2e00ed 100644 --- a/Sources/HTTPTypes/NIOLock.swift +++ b/Sources/HTTPTypes/NIOLock.swift @@ -1,5 +1,18 @@ //===----------------------------------------------------------------------===// // +// This source file is part of the Swift open source project +// +// Copyright (c) 2024 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of Swift project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// +//===----------------------------------------------------------------------===// +// // This source file is part of the SwiftNIO open source project // // Copyright (c) 2017-2024 Apple Inc. and the SwiftNIO project authors