Skip to content

Commit b6dbc8a

Browse files
committed
Merge branch 'develop'
2 parents 016845f + 72db371 commit b6dbc8a

File tree

9 files changed

+64
-14
lines changed

9 files changed

+64
-14
lines changed

.github/workflows/swift.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- swift:5.5.3-xenial
1717
- swift:5.6.1-bionic
1818
- swift:5.7.2-focal
19+
- swift:5.8-jammy
1920
container: ${{ matrix.image }}
2021
steps:
2122
- name: Checkout Repository

Sources/MacroCore/Buffer/BufferData.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
// Macro
44
//
55
// Created by Helge Heß.
6-
// Copyright © 2020-2021 ZeeZide GmbH. All rights reserved.
6+
// Copyright © 2020-2023 ZeeZide GmbH. All rights reserved.
77
//
88

99
#if canImport(Foundation)
1010

1111
import struct Foundation.Data
12+
import NIOCore
13+
import NIOFoundationCompat
1214

1315
public extension Buffer {
1416

Sources/MacroCore/Buffer/BufferDeprecations.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
// Macro
44
//
55
// Created by Helge Heß.
6-
// Copyright © 2020-2021 ZeeZide GmbH. All rights reserved.
6+
// Copyright © 2020-2023 ZeeZide GmbH. All rights reserved.
77
//
88

99
#if canImport(Foundation)
10+
import Foundation
1011

1112
public extension Buffer {
1213

Sources/MacroCore/Buffer/BufferHexEncoding.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
// Macro
44
//
55
// Created by Helge Heß.
6-
// Copyright © 2020-2021 ZeeZide GmbH. All rights reserved.
6+
// Copyright © 2020-2023 ZeeZide GmbH. All rights reserved.
77
//
88

9+
import NIOCore
10+
911
@usableFromInline
1012
internal let hexAlphabet = "0123456789abcdef".unicodeScalars.map { $0 }
1113
@usableFromInline

Sources/MacroCore/JSON.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,15 @@ public extension JSONModule {
103103

104104
// MARK: - Encodable versions
105105

106+
@inlinable
106107
static func dataify<C: Encodable>(_ object : C?,
107108
outputFormatting:
108109
JSONEncoder.OutputFormatting
109110
= _defaultJSONEncoderOptions)
110111
-> Foundation.Data?
111112
{
112113
do {
113-
let encoder = makeEncoder()
114+
let encoder = JSONEncoderWithISO8601()
114115
encoder.outputFormatting = outputFormatting
115116
return try encoder.encode(object)
116117
}
@@ -158,14 +159,15 @@ public let _defaultJSONEncoderOptions : JSONEncoder.OutputFormatting = {
158159
public extension WritableStreamType where WritablePayload == Buffer {
159160

160161
@discardableResult
162+
@inlinable
161163
func write<S: Encodable>(_ jsonObject: S,
162164
outputFormatting:
163165
JSONEncoder.OutputFormatting
164166
= _defaultJSONEncoderOptions,
165167
whenDone : @escaping () -> Void = {}) -> Bool
166168
{
167169
do {
168-
let encoder = makeEncoder()
170+
let encoder = JSONEncoderWithISO8601()
169171
encoder.outputFormatting = outputFormatting
170172
let data = try encoder.encode(jsonObject)
171173
return write(data, whenDone: whenDone)
@@ -205,7 +207,8 @@ public extension WritableStreamType where WritablePayload == Buffer {
205207
}
206208

207209
/// It is undocumented whether the encoder is threadsafe, so assume it is not.
208-
fileprivate func makeEncoder() -> JSONEncoder {
210+
@usableFromInline
211+
func JSONEncoderWithISO8601() -> JSONEncoder {
209212
let encoder = JSONEncoder()
210213
if #available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
211214
// According to https://github.com/NozeIO/MicroExpress/pull/13 the default

Sources/MacroCore/JSStubs/StringStubs.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
// Macro
44
//
55
// Created by Helge Hess.
6-
// Copyright © 2021 ZeeZide GmbH. All rights reserved.
6+
// Copyright © 2021-2023 ZeeZide GmbH. All rights reserved.
77
//
88

9+
#if canImport(Foundation)
10+
import Foundation
11+
912
@inlinable
1013
public func parseInt(_ string: String, _ radix: Int = 10) -> Int? {
1114
guard radix >= 2 && radix <= 36 else { return nil }
@@ -31,6 +34,7 @@ public extension String {
3134
return trimmingCharacters(in: .whitespacesAndNewlines)
3235
}
3336
}
37+
#endif // canImport(Foundation)
3438

3539
public extension Sequence where Element: StringProtocol {
3640

Sources/MacroCore/Process/Process.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
// Macro
44
//
55
// Created by Helge Hess.
6-
// Copyright © 2020-2021 ZeeZide GmbH. All rights reserved.
6+
// Copyright © 2020-2023 ZeeZide GmbH. All rights reserved.
77
//
88

9-
import class Foundation.ProcessInfo
109
import xsys
10+
import NIO
1111

1212
#if os(Windows)
1313
import WinSDK

Sources/MacroCore/StringEncoding.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
// Macro
44
//
55
// Created by Helge Hess.
6-
// Copyright © 2020-2021 ZeeZide GmbH. All rights reserved.
6+
// Copyright © 2020-2023 ZeeZide GmbH. All rights reserved.
77
//
88

9+
#if canImport(Foundation)
10+
import Foundation
11+
912
@usableFromInline
1013
internal let stringEncodingNames : Set<String> = [
1114
"utf8", "utf-8",
@@ -66,3 +69,4 @@ public enum CharsetConversionError: Swift.Error {
6669
case failedToConverData (encoding: String.Encoding)
6770
case failedToConvertString(encoding: String.Encoding)
6871
}
72+
#endif // canImport(Foundation)

Sources/http/BasicAuth.swift

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@
33
// Macro
44
//
55
// Created by Helge Hess.
6-
// Copyright © 2020 ZeeZide GmbH. All rights reserved.
6+
// Copyright © 2020-2023 ZeeZide GmbH. All rights reserved.
77
//
88

99
public enum BasicAuthModule {}
1010
public typealias basicAuth = BasicAuthModule
1111

12-
import Foundation
12+
#if canImport(Foundation)
13+
import Foundation
14+
#endif
1315
import enum MacroCore.CharsetConversionError
1416

1517
public extension BasicAuthModule {
1618

19+
/**
20+
* HTTP Basic Authentication credentials as extracted by the
21+
* ``auth(_:encoding:)`` function, i.e. the name/password associated
22+
* with an ``IncomingMessage``.
23+
*/
1724
struct Credentials {
1825
public let name : String
1926
public let pass : String
@@ -28,10 +35,35 @@ public extension BasicAuthModule {
2835
case stringEncodingError
2936
}
3037

31-
static func auth(_ req: IncomingMessage, encoding: String.Encoding = .utf8)
38+
#if canImport(Foundation) // `String.Encoding.utf8`, provide alternative!
39+
/**
40+
* Extract HTTP Basic authentication credentials (name/pass) from the given
41+
* ```IncomingMessage```.
42+
*
43+
* - Parameters:
44+
* - request: The ``IncomingMessage`` containing the `Authorization`
45+
* header.
46+
* - encoding: The encoding the String is using.
47+
* - Throws: ``BasicAuthError/missingAuthorizationHeader`` if there is no
48+
* `Authorization` header,
49+
* ``BasicAuthError/unexpectedAuthorizationHeaderType`` if the header
50+
* existed, but wasn't a `String`,
51+
* ``BasicAuthError/invalidAuthorizationHeader`` if the header value
52+
* syntax could not be parsed,
53+
* ``BasicAuthError/differentAuthorization`` if the header was set, but
54+
* wasn't HTTP Basic authentication,
55+
* ``BasicAuthError/invalidBasicAuthorizationHeader`` if the header was
56+
* set, but didn't had the right Basic auth syntax,
57+
* ``BasicAuthError/invalidBasicAuthorizationHeader`` if the header could
58+
* be parsed, but the values could not be parsed using the given
59+
* `encoding` specified.
60+
* - Returns: The ``Credentials``, i.e. `name`/`pass`.
61+
*/
62+
static func auth(_ request: IncomingMessage,
63+
encoding: String.Encoding = .utf8)
3264
throws -> Credentials
3365
{
34-
guard let authorization = req.getHeader("Authorization") else {
66+
guard let authorization = request.getHeader("Authorization") else {
3567
throw BasicAuthError.missingAuthorizationHeader
3668
}
3769
guard let authString = authorization as? String else {
@@ -69,4 +101,5 @@ public extension BasicAuthModule {
69101
pass: String(string[colIdx..<string.endIndex])
70102
)
71103
}
104+
#endif // canImport(Foundation)
72105
}

0 commit comments

Comments
 (0)