mirror of
https://github.com/apple/swift-http-structured-headers
synced 2026-11-27 05:04:20 +00:00
Migrate to GitHub Actions (#42)
Migrate CI to use GitHub Actions. Motivation: To migrate to GitHub actions and centralised infrastructure. Modifications: Changes of note: * Adopt swift-format using rules from SwiftNIO * Remove scripts and docker files which are no longer needed Result: Feature parity with old CI.
This commit is contained in:
1 parent
b0bf94fb2d
commit
8b35bf45bf
41 files changed
+625
-757
No files matched your search
@@ -77,7 +77,8 @@ extension BareInnerListDecoder: UnkeyedDecodingContainer {
|
||||
}
|
||||
}
|
||||
|
||||
mutating func nestedContainer<NestedKey>(keyedBy type: NestedKey.Type) throws -> KeyedDecodingContainer<NestedKey> where NestedKey: CodingKey {
|
||||
mutating func nestedContainer<NestedKey>(keyedBy type: NestedKey.Type) throws -> KeyedDecodingContainer<NestedKey>
|
||||
where NestedKey: CodingKey {
|
||||
// This is a request to decode a full item. We decode the next entry and increment the index.
|
||||
guard !self.isAtEnd else {
|
||||
throw StructuredHeaderError.indexOutOfRange
|
||||
|
||||
@@ -62,6 +62,18 @@ extension BareItemDecoder: SingleValueDecodingContainer {
|
||||
try self._decodeFixedWidthInteger(type)
|
||||
}
|
||||
|
||||
#if compiler(>=6.0)
|
||||
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
|
||||
func decode(_ type: UInt128.Type) throws -> UInt128 {
|
||||
try self._decodeFixedWidthInteger(type)
|
||||
}
|
||||
|
||||
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
|
||||
func decode(_ type: Int128.Type) throws -> Int128 {
|
||||
try self._decodeFixedWidthInteger(type)
|
||||
}
|
||||
#endif
|
||||
|
||||
func decode(_ type: UInt.Type) throws -> UInt {
|
||||
try self._decodeFixedWidthInteger(type)
|
||||
}
|
||||
@@ -114,9 +126,11 @@ extension BareItemDecoder: SingleValueDecodingContainer {
|
||||
throw StructuredHeaderError.invalidTypeForItem
|
||||
}
|
||||
|
||||
return Decimal(sign: pseudoDecimal.mantissa > 0 ? .plus : .minus,
|
||||
exponent: Int(pseudoDecimal.exponent),
|
||||
significand: Decimal(pseudoDecimal.mantissa.magnitude))
|
||||
return Decimal(
|
||||
sign: pseudoDecimal.mantissa > 0 ? .plus : .minus,
|
||||
exponent: Int(pseudoDecimal.exponent),
|
||||
significand: Decimal(pseudoDecimal.mantissa.magnitude)
|
||||
)
|
||||
}
|
||||
|
||||
func decodeNil() -> Bool {
|
||||
|
||||
@@ -60,7 +60,10 @@ extension DictionaryKeyedContainer: KeyedDecodingContainerProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func nestedContainer<NestedKey: CodingKey>(keyedBy type: NestedKey.Type, forKey key: Key) throws -> KeyedDecodingContainer<NestedKey> {
|
||||
func nestedContainer<NestedKey: CodingKey>(
|
||||
keyedBy type: NestedKey.Type,
|
||||
forKey key: Key
|
||||
) throws -> KeyedDecodingContainer<NestedKey> {
|
||||
try self.decoder.push(_StructuredHeaderCodingKey(key, keyDecodingStrategy: self.decoder.keyDecodingStrategy))
|
||||
defer {
|
||||
self.decoder.pop()
|
||||
|
||||
@@ -65,7 +65,10 @@ extension KeyedInnerListDecoder: KeyedDecodingContainerProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func nestedContainer<NestedKey: CodingKey>(keyedBy type: NestedKey.Type, forKey key: Key) throws -> KeyedDecodingContainer<NestedKey> {
|
||||
func nestedContainer<NestedKey: CodingKey>(
|
||||
keyedBy type: NestedKey.Type,
|
||||
forKey key: Key
|
||||
) throws -> KeyedDecodingContainer<NestedKey> {
|
||||
try self.decoder.push(_StructuredHeaderCodingKey(key, keyDecodingStrategy: self.decoder.keyDecodingStrategy))
|
||||
defer {
|
||||
self.decoder.pop()
|
||||
|
||||
@@ -65,7 +65,10 @@ extension KeyedItemDecoder: KeyedDecodingContainerProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func nestedContainer<NestedKey: CodingKey>(keyedBy type: NestedKey.Type, forKey key: Key) throws -> KeyedDecodingContainer<NestedKey> {
|
||||
func nestedContainer<NestedKey: CodingKey>(
|
||||
keyedBy type: NestedKey.Type,
|
||||
forKey key: Key
|
||||
) throws -> KeyedDecodingContainer<NestedKey> {
|
||||
try self.decoder.push(_StructuredHeaderCodingKey(key, keyDecodingStrategy: self.decoder.keyDecodingStrategy))
|
||||
defer {
|
||||
self.decoder.pop()
|
||||
|
||||
@@ -65,7 +65,10 @@ extension KeyedTopLevelListDecoder: KeyedDecodingContainerProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func nestedContainer<NestedKey: CodingKey>(keyedBy type: NestedKey.Type, forKey key: Key) throws -> KeyedDecodingContainer<NestedKey> {
|
||||
func nestedContainer<NestedKey: CodingKey>(
|
||||
keyedBy type: NestedKey.Type,
|
||||
forKey key: Key
|
||||
) throws -> KeyedDecodingContainer<NestedKey> {
|
||||
try self.decoder.push(_StructuredHeaderCodingKey(key, keyDecodingStrategy: self.decoder.keyDecodingStrategy))
|
||||
defer {
|
||||
self.decoder.pop()
|
||||
|
||||
@@ -60,7 +60,10 @@ extension ParametersDecoder: KeyedDecodingContainerProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func nestedContainer<NestedKey: CodingKey>(keyedBy type: NestedKey.Type, forKey key: Key) throws -> KeyedDecodingContainer<NestedKey> {
|
||||
func nestedContainer<NestedKey: CodingKey>(
|
||||
keyedBy type: NestedKey.Type,
|
||||
forKey key: Key
|
||||
) throws -> KeyedDecodingContainer<NestedKey> {
|
||||
try self.decoder.push(_StructuredHeaderCodingKey(key, keyDecodingStrategy: self.decoder.keyDecodingStrategy))
|
||||
defer {
|
||||
self.decoder.pop()
|
||||
|
||||
@@ -46,7 +46,10 @@ extension StructuredFieldValueDecoder {
|
||||
/// - data: The bytes of the structured header field.
|
||||
/// - throws: If the header field could not be parsed, or could not be decoded.
|
||||
/// - returns: An object of type `StructuredField`.
|
||||
public func decode<StructuredField: StructuredFieldValue, BaseData: RandomAccessCollection>(_ type: StructuredField.Type = StructuredField.self, from data: BaseData) throws -> StructuredField where BaseData.Element == UInt8 {
|
||||
public func decode<StructuredField: StructuredFieldValue, BaseData: RandomAccessCollection>(
|
||||
_ type: StructuredField.Type = StructuredField.self,
|
||||
from data: BaseData
|
||||
) throws -> StructuredField where BaseData.Element == UInt8 {
|
||||
switch StructuredField.structuredFieldType {
|
||||
case .item:
|
||||
return try self.decodeItemField(from: data)
|
||||
@@ -64,7 +67,10 @@ extension StructuredFieldValueDecoder {
|
||||
/// - data: The bytes of the structured header field.
|
||||
/// - throws: If the header field could not be parsed, or could not be decoded.
|
||||
/// - returns: An object of type `StructuredField`.
|
||||
private func decodeDictionaryField<StructuredField: Decodable, BaseData: RandomAccessCollection>(_ type: StructuredField.Type = StructuredField.self, from data: BaseData) throws -> StructuredField where BaseData.Element == UInt8 {
|
||||
private func decodeDictionaryField<StructuredField: Decodable, BaseData: RandomAccessCollection>(
|
||||
_ type: StructuredField.Type = StructuredField.self,
|
||||
from data: BaseData
|
||||
) throws -> StructuredField where BaseData.Element == UInt8 {
|
||||
let parser = StructuredFieldValueParser(data)
|
||||
let decoder = _StructuredFieldDecoder(parser, keyDecodingStrategy: self.keyDecodingStrategy)
|
||||
try decoder.parseDictionaryField()
|
||||
@@ -78,7 +84,10 @@ extension StructuredFieldValueDecoder {
|
||||
/// - data: The bytes of the structured header field.
|
||||
/// - throws: If the header field could not be parsed, or could not be decoded.
|
||||
/// - returns: An object of type `StructuredField`.
|
||||
private func decodeListField<StructuredField: Decodable, BaseData: RandomAccessCollection>(_ type: StructuredField.Type = StructuredField.self, from data: BaseData) throws -> StructuredField where BaseData.Element == UInt8 {
|
||||
private func decodeListField<StructuredField: Decodable, BaseData: RandomAccessCollection>(
|
||||
_ type: StructuredField.Type = StructuredField.self,
|
||||
from data: BaseData
|
||||
) throws -> StructuredField where BaseData.Element == UInt8 {
|
||||
let parser = StructuredFieldValueParser(data)
|
||||
let decoder = _StructuredFieldDecoder(parser, keyDecodingStrategy: self.keyDecodingStrategy)
|
||||
try decoder.parseListField()
|
||||
@@ -92,7 +101,10 @@ extension StructuredFieldValueDecoder {
|
||||
/// - data: The bytes of the structured header field.
|
||||
/// - throws: If the header field could not be parsed, or could not be decoded.
|
||||
/// - returns: An object of type `StructuredField`.
|
||||
private func decodeItemField<StructuredField: Decodable, BaseData: RandomAccessCollection>(_ type: StructuredField.Type = StructuredField.self, from data: BaseData) throws -> StructuredField where BaseData.Element == UInt8 {
|
||||
private func decodeItemField<StructuredField: Decodable, BaseData: RandomAccessCollection>(
|
||||
_ type: StructuredField.Type = StructuredField.self,
|
||||
from data: BaseData
|
||||
) throws -> StructuredField where BaseData.Element == UInt8 {
|
||||
let parser = StructuredFieldValueParser(data)
|
||||
let decoder = _StructuredFieldDecoder(parser, keyDecodingStrategy: self.keyDecodingStrategy)
|
||||
try decoder.parseItemField()
|
||||
@@ -120,7 +132,10 @@ class _StructuredFieldDecoder<BaseData: RandomAccessCollection> where BaseData.E
|
||||
|
||||
var keyDecodingStrategy: StructuredFieldValueDecoder.KeyDecodingStrategy?
|
||||
|
||||
init(_ parser: StructuredFieldValueParser<BaseData>, keyDecodingStrategy: StructuredFieldValueDecoder.KeyDecodingStrategy?) {
|
||||
init(
|
||||
_ parser: StructuredFieldValueParser<BaseData>,
|
||||
keyDecodingStrategy: StructuredFieldValueDecoder.KeyDecodingStrategy?
|
||||
) {
|
||||
self.parser = parser
|
||||
self._codingStack = []
|
||||
self.keyDecodingStrategy = keyDecodingStrategy
|
||||
|
||||
@@ -77,7 +77,8 @@ extension TopLevelListDecoder: UnkeyedDecodingContainer {
|
||||
}
|
||||
}
|
||||
|
||||
mutating func nestedContainer<NestedKey>(keyedBy type: NestedKey.Type) throws -> KeyedDecodingContainer<NestedKey> where NestedKey: CodingKey {
|
||||
mutating func nestedContainer<NestedKey>(keyedBy type: NestedKey.Type) throws -> KeyedDecodingContainer<NestedKey>
|
||||
where NestedKey: CodingKey {
|
||||
// This is a request to decode a full item. We decode the next entry and increment the index.
|
||||
guard !self.isAtEnd else {
|
||||
throw StructuredHeaderError.indexOutOfRange
|
||||
|
||||
@@ -93,8 +93,11 @@ extension StructuredFieldKeyedEncodingContainer: KeyedEncodingContainerProtocol
|
||||
try self.encoder.encode(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
mutating func nestedContainer<NestedKey>(keyedBy keyType: NestedKey.Type, forKey key: Key) -> KeyedEncodingContainer<NestedKey> where NestedKey: CodingKey {
|
||||
return self.encoder.container(keyedBy: keyType)
|
||||
mutating func nestedContainer<NestedKey>(
|
||||
keyedBy keyType: NestedKey.Type,
|
||||
forKey key: Key
|
||||
) -> KeyedEncodingContainer<NestedKey> where NestedKey: CodingKey {
|
||||
self.encoder.container(keyedBy: keyType)
|
||||
}
|
||||
|
||||
mutating func nestedUnkeyedContainer(forKey key: Key) -> UnkeyedEncodingContainer {
|
||||
|
||||
@@ -97,8 +97,9 @@ extension StructuredFieldUnkeyedEncodingContainer: UnkeyedEncodingContainer {
|
||||
try self.encoder.append(value)
|
||||
}
|
||||
|
||||
mutating func nestedContainer<NestedKey>(keyedBy keyType: NestedKey.Type) -> KeyedEncodingContainer<NestedKey> where NestedKey: CodingKey {
|
||||
return self.encoder.container(keyedBy: keyType)
|
||||
mutating func nestedContainer<NestedKey>(keyedBy keyType: NestedKey.Type) -> KeyedEncodingContainer<NestedKey>
|
||||
where NestedKey: CodingKey {
|
||||
self.encoder.container(keyedBy: keyType)
|
||||
}
|
||||
|
||||
mutating func nestedUnkeyedContainer() -> UnkeyedEncodingContainer {
|
||||
|
||||
@@ -103,11 +103,16 @@ class _StructuredFieldEncoder {
|
||||
|
||||
internal var keyEncodingStrategy: StructuredFieldValueEncoder.KeyEncodingStrategy?
|
||||
|
||||
init(_ serializer: StructuredFieldValueSerializer, keyEncodingStrategy: StructuredFieldValueEncoder.KeyEncodingStrategy?) {
|
||||
init(
|
||||
_ serializer: StructuredFieldValueSerializer,
|
||||
keyEncodingStrategy: StructuredFieldValueEncoder.KeyEncodingStrategy?
|
||||
) {
|
||||
self.serializer = serializer
|
||||
self._codingPath = []
|
||||
self.keyEncodingStrategy = keyEncodingStrategy
|
||||
self.currentStackEntry = CodingStackEntry(key: .init(stringValue: ""), storage: .itemHeader) // This default doesn't matter right now.
|
||||
|
||||
// This default doesn't matter right now.
|
||||
self.currentStackEntry = CodingStackEntry(key: .init(stringValue: ""), storage: .itemHeader)
|
||||
}
|
||||
|
||||
fileprivate func encodeDictionaryField<StructuredField: Encodable>(_ data: StructuredField) throws -> [UInt8] {
|
||||
@@ -121,7 +126,7 @@ class _StructuredFieldEncoder {
|
||||
// No encoding happened.
|
||||
return []
|
||||
case .listHeader, .list, .itemHeader, .item, .bareInnerList, .innerList,
|
||||
.parameters, .itemOrInnerList:
|
||||
.parameters, .itemOrInnerList:
|
||||
throw StructuredHeaderError.invalidTypeForItem
|
||||
}
|
||||
}
|
||||
@@ -137,7 +142,7 @@ class _StructuredFieldEncoder {
|
||||
// No encoding happened
|
||||
return []
|
||||
case .dictionaryHeader, .dictionary, .itemHeader, .item, .bareInnerList, .innerList,
|
||||
.parameters, .itemOrInnerList:
|
||||
.parameters, .itemOrInnerList:
|
||||
throw StructuredHeaderError.invalidTypeForItem
|
||||
}
|
||||
}
|
||||
@@ -166,7 +171,7 @@ class _StructuredFieldEncoder {
|
||||
// No encoding happened
|
||||
return []
|
||||
case .dictionaryHeader, .dictionary, .listHeader, .list, .bareInnerList, .innerList,
|
||||
.parameters, .itemOrInnerList:
|
||||
.parameters, .itemOrInnerList:
|
||||
throw StructuredHeaderError.invalidTypeForItem
|
||||
}
|
||||
}
|
||||
@@ -197,7 +202,7 @@ extension _StructuredFieldEncoder: Encoder {
|
||||
}
|
||||
|
||||
func container<Key>(keyedBy type: Key.Type) -> KeyedEncodingContainer<Key> where Key: CodingKey {
|
||||
return KeyedEncodingContainer(StructuredFieldKeyedEncodingContainer(encoder: self))
|
||||
KeyedEncodingContainer(StructuredFieldKeyedEncodingContainer(encoder: self))
|
||||
}
|
||||
|
||||
func unkeyedContainer() -> UnkeyedEncodingContainer {
|
||||
@@ -255,6 +260,13 @@ extension _StructuredFieldEncoder: SingleValueEncodingContainer {
|
||||
try self._encodeFixedWidthInteger(value)
|
||||
}
|
||||
|
||||
#if compiler(>=6.0)
|
||||
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
|
||||
func encode(_ value: Int128) throws {
|
||||
try self._encodeFixedWidthInteger(value)
|
||||
}
|
||||
#endif
|
||||
|
||||
func encode(_ value: UInt) throws {
|
||||
try self._encodeFixedWidthInteger(value)
|
||||
}
|
||||
@@ -275,13 +287,20 @@ extension _StructuredFieldEncoder: SingleValueEncodingContainer {
|
||||
try self._encodeFixedWidthInteger(value)
|
||||
}
|
||||
|
||||
#if compiler(>=6.0)
|
||||
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
|
||||
func encode(_ value: UInt128) throws {
|
||||
try self._encodeFixedWidthInteger(value)
|
||||
}
|
||||
#endif
|
||||
|
||||
func encode(_ data: Data) throws {
|
||||
let encoded = data.base64EncodedString()
|
||||
try self.currentStackEntry.storage.insertBareItem(.undecodedByteSequence(encoded))
|
||||
}
|
||||
|
||||
func encode(_ data: Decimal) throws {
|
||||
let significand = (data.significand.magnitude as NSNumber).intValue // Yes, really.
|
||||
let significand = (data.significand.magnitude as NSNumber).intValue // Yes, really.
|
||||
guard let exponent = Int8(exactly: data.exponent) else {
|
||||
throw StructuredHeaderError.invalidIntegerOrDecimal
|
||||
}
|
||||
@@ -438,7 +457,7 @@ extension _StructuredFieldEncoder {
|
||||
}
|
||||
|
||||
func append(_ value: Decimal) throws {
|
||||
let significand = (value.significand.magnitude as NSNumber).intValue // Yes, really.
|
||||
let significand = (value.significand.magnitude as NSNumber).intValue // Yes, really.
|
||||
guard let exponent = Int8(exactly: value.exponent) else {
|
||||
throw StructuredHeaderError.invalidIntegerOrDecimal
|
||||
}
|
||||
@@ -601,11 +620,14 @@ extension _StructuredFieldEncoder {
|
||||
|
||||
func encode(_ value: Data, forKey key: String) throws {
|
||||
let key = self.sanitizeKey(key)
|
||||
try self.currentStackEntry.storage.insertBareItem(.undecodedByteSequence(value.base64EncodedString()), atKey: key)
|
||||
try self.currentStackEntry.storage.insertBareItem(
|
||||
.undecodedByteSequence(value.base64EncodedString()),
|
||||
atKey: key
|
||||
)
|
||||
}
|
||||
|
||||
func encode(_ value: Decimal, forKey key: String) throws {
|
||||
let significand = (value.significand.magnitude as NSNumber).intValue // Yes, really.
|
||||
let significand = (value.significand.magnitude as NSNumber).intValue // Yes, really.
|
||||
guard let exponent = Int8(exactly: value.exponent) else {
|
||||
throw StructuredHeaderError.invalidIntegerOrDecimal
|
||||
}
|
||||
@@ -715,7 +737,7 @@ extension _StructuredFieldEncoder {
|
||||
}
|
||||
|
||||
case .list, .itemHeader, .bareInnerList,
|
||||
.parameters:
|
||||
.parameters:
|
||||
throw StructuredHeaderError.invalidTypeForItem
|
||||
}
|
||||
}
|
||||
@@ -914,10 +936,12 @@ extension _StructuredFieldEncoder {
|
||||
|
||||
case .itemOrInnerList(let params):
|
||||
// This is an inner list.
|
||||
self = .innerList(InnerList(bareInnerList: [Item(bareItem: bareItem, parameters: [:])], parameters: params))
|
||||
self = .innerList(
|
||||
InnerList(bareInnerList: [Item(bareItem: bareItem, parameters: [:])], parameters: params)
|
||||
)
|
||||
|
||||
case .dictionaryHeader, .dictionary, .itemHeader, .item,
|
||||
.parameters:
|
||||
.parameters:
|
||||
throw StructuredHeaderError.invalidTypeForItem
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user