mirror of
https://github.com/apple/swift-http-structured-headers
synced 2026-11-24 04:37:50 +00:00
[RFC 9651] Implement adjustments for backward compatible update (#40)
Motivation: `swift-http-structured-headers` has to be updated to [RFC 9651](https://www.ietf.org/rfc/rfc9651.html). And it will be convenient for users to have this update as a SemVer minor. Modifications: - Deprecate the `BareItem` type and replace it with `RFC9651BareItem`, retaining existing behaviours. Updates for the new RFC will be based on `RFC9651BareItem`. Result: The library can be updated to the new RFC in a backward-compatible manner.
This commit is contained in:
1 parent
8cc27e208a
commit
f069b10a87
11 files changed
+218
-53
No files matched your search
@@ -15,11 +15,11 @@ import Foundation
|
||||
import RawStructuredFieldValues
|
||||
|
||||
struct BareItemDecoder {
|
||||
private var item: BareItem
|
||||
private var item: RFC9651BareItem
|
||||
|
||||
private var _codingPath: [_StructuredHeaderCodingKey]
|
||||
|
||||
init(_ item: BareItem, codingPath: [_StructuredHeaderCodingKey]) {
|
||||
init(_ item: RFC9651BareItem, codingPath: [_StructuredHeaderCodingKey]) {
|
||||
self.item = item
|
||||
self._codingPath = codingPath
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@ import Foundation
|
||||
import RawStructuredFieldValues
|
||||
|
||||
struct ParametersDecoder<Key: CodingKey, BaseData: RandomAccessCollection> where BaseData.Element == UInt8 {
|
||||
private var parameters: OrderedMap<String, BareItem>
|
||||
private var parameters: OrderedMap<String, RFC9651BareItem>
|
||||
|
||||
private var decoder: _StructuredFieldDecoder<BaseData>
|
||||
|
||||
init(_ parameters: OrderedMap<String, BareItem>, decoder: _StructuredFieldDecoder<BaseData>) {
|
||||
init(_ parameters: OrderedMap<String, RFC9651BareItem>, decoder: _StructuredFieldDecoder<BaseData>) {
|
||||
self.parameters = parameters
|
||||
self.decoder = decoder
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ extension _StructuredFieldDecoder: Decoder {
|
||||
// We have single value containers for items and bareItems.
|
||||
switch self.currentElement! {
|
||||
case .item(let item):
|
||||
return BareItemDecoder(item.bareItem, codingPath: self._codingStack.map { $0.key })
|
||||
return BareItemDecoder(item.rfc9651BareItem, codingPath: self._codingStack.map { $0.key })
|
||||
case .bareItem(let bareItem):
|
||||
return BareItemDecoder(bareItem, codingPath: self._codingStack.map { $0.key })
|
||||
case .dictionary, .list, .innerList, .bareInnerList, .parameters:
|
||||
@@ -224,9 +224,9 @@ extension _StructuredFieldDecoder {
|
||||
case list([ItemOrInnerList])
|
||||
case item(Item)
|
||||
case innerList(InnerList)
|
||||
case bareItem(BareItem)
|
||||
case bareItem(RFC9651BareItem)
|
||||
case bareInnerList(BareInnerList)
|
||||
case parameters(OrderedMap<String, BareItem>)
|
||||
case parameters(OrderedMap<String, RFC9651BareItem>)
|
||||
|
||||
func innerElement(for key: _StructuredHeaderCodingKey) throws -> Element {
|
||||
switch self {
|
||||
@@ -263,9 +263,9 @@ extension _StructuredFieldDecoder {
|
||||
// Two keys, "item" and "parameters".
|
||||
switch key.stringValue {
|
||||
case "item":
|
||||
return .bareItem(item.bareItem)
|
||||
return .bareItem(item.rfc9651BareItem)
|
||||
case "parameters":
|
||||
return .parameters(item.parameters)
|
||||
return .parameters(item.rfc9651Parameters)
|
||||
default:
|
||||
throw StructuredHeaderError.invalidTypeForItem
|
||||
}
|
||||
@@ -280,7 +280,7 @@ extension _StructuredFieldDecoder {
|
||||
case "items":
|
||||
return .bareInnerList(innerList.bareInnerList)
|
||||
case "parameters":
|
||||
return .parameters(innerList.parameters)
|
||||
return .parameters(innerList.rfc9651Parameters)
|
||||
default:
|
||||
throw StructuredHeaderError.invalidTypeForItem
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user