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
@@ -766,14 +766,14 @@ extension _StructuredFieldEncoder {
|
||||
case innerList(InnerList)
|
||||
case item(PartialItem)
|
||||
case bareInnerList(BareInnerList)
|
||||
case parameters(OrderedMap<String, BareItem>)
|
||||
case itemOrInnerList(OrderedMap<String, BareItem>)
|
||||
case parameters(OrderedMap<String, RFC9651BareItem>)
|
||||
case itemOrInnerList(OrderedMap<String, RFC9651BareItem>)
|
||||
|
||||
/// A helper struct used to tolerate the fact that we need partial items,
|
||||
/// but our `Item` struct doesn't like that much.
|
||||
struct PartialItem {
|
||||
var bareItem: BareItem?
|
||||
var parameters: OrderedMap<String, BareItem>
|
||||
var bareItem: RFC9651BareItem?
|
||||
var parameters: OrderedMap<String, RFC9651BareItem>
|
||||
}
|
||||
|
||||
/// This is called when a complete object has been built.
|
||||
@@ -787,7 +787,7 @@ extension _StructuredFieldEncoder {
|
||||
self = .item(item)
|
||||
|
||||
case (.innerList(var list), .parameters(let params)) where key.stringValue == "parameters":
|
||||
list.parameters = params
|
||||
list.rfc9651Parameters = params
|
||||
self = .innerList(list)
|
||||
|
||||
case (.innerList(var list), .bareInnerList(let bare)) where key.stringValue == "items":
|
||||
@@ -846,7 +846,7 @@ extension _StructuredFieldEncoder {
|
||||
///
|
||||
/// If the key is missing we will require the type to be `item`, in which case
|
||||
/// this will be for the "item" key.
|
||||
mutating func insertBareItem(_ bareItem: BareItem, atKey key: String? = nil) throws {
|
||||
mutating func insertBareItem(_ bareItem: RFC9651BareItem, atKey key: String? = nil) throws {
|
||||
switch self {
|
||||
case .itemHeader:
|
||||
guard key == nil || key == "item" else {
|
||||
@@ -895,7 +895,7 @@ extension _StructuredFieldEncoder {
|
||||
|
||||
/// Appends a bare item to the given container. This must be a list-type
|
||||
/// container that stores either bare items, or items.
|
||||
mutating func appendBareItem(_ bareItem: BareItem) throws {
|
||||
mutating func appendBareItem(_ bareItem: RFC9651BareItem) throws {
|
||||
switch self {
|
||||
case .listHeader:
|
||||
self = .list([.item(Item(bareItem: bareItem, parameters: [:]))])
|
||||
|
||||
Reference in new issue
Block a user