11import Foundation
2+ import OrderedCollections
23
34/// A parseable URL request.
45///
@@ -76,9 +77,9 @@ public struct URLRequestData: Equatable, _EmptyInitializable {
7677 host: String ? = nil ,
7778 port: Int ? = nil ,
7879 path: String = " " ,
79- query: [ String : [ String ? ] ] = [ : ] ,
80+ query: OrderedDictionary < String , [ String ? ] > = [ : ] ,
8081 fragment: String ? = nil ,
81- headers: [ String : [ String ? ] ] = [ : ] ,
82+ headers: OrderedDictionary < String , [ String ? ] > = [ : ] ,
8283 body: Data ? = nil
8384 ) {
8485 self . body = body
@@ -99,13 +100,13 @@ public struct URLRequestData: Equatable, _EmptyInitializable {
99100 /// Used by ``URLRequestData`` to model query parameters and headers in a way that can be
100101 /// efficiently parsed.
101102 public struct Fields {
102- public var fields : [ String : ArraySlice < Substring ? > ]
103+ public var fields : OrderedDictionary < String , ArraySlice < Substring ? > >
103104
104105 @usableFromInline var isNameCaseSensitive : Bool
105106
106107 @inlinable
107108 public init (
108- _ fields: [ String : ArraySlice < Substring ? > ] = [ : ] ,
109+ _ fields: OrderedDictionary < String , ArraySlice < Substring ? > > = [ : ] ,
109110 isNameCaseSensitive: Bool
110111 ) {
111112 self . fields = [ : ]
@@ -152,9 +153,9 @@ extension URLRequestData: Codable {
152153 host: try container. decodeIfPresent ( String . self, forKey: . host) ,
153154 port: try container. decodeIfPresent ( Int . self, forKey: . port) ,
154155 path: try container. decodeIfPresent ( String . self, forKey: . path) ?? " " ,
155- query: try container. decodeIfPresent ( [ String : [ String ? ] ] . self, forKey: . query) ?? [ : ] ,
156+ query: try container. decodeIfPresent ( OrderedDictionary < String , [ String ? ] > . self, forKey: . query) ?? [ : ] ,
156157 fragment: try container. decodeIfPresent ( String . self, forKey: . fragment) ,
157- headers: try container. decodeIfPresent ( [ String : [ String ? ] ] . self, forKey: . headers) ?? [ : ] ,
158+ headers: try container. decodeIfPresent ( OrderedDictionary < String , [ String ? ] > . self, forKey: . headers) ?? [ : ] ,
158159 body: try container. decodeIfPresent ( Data . self, forKey: . body)
159160 )
160161 }
@@ -219,27 +220,27 @@ extension URLRequestData: Hashable {
219220}
220221
221222extension URLRequestData . Fields : Collection {
222- public typealias Element = Dictionary < String , ArraySlice < Substring ? > > . Element
223- public typealias Index = Dictionary < String , ArraySlice < Substring ? > > . Index
223+ public typealias Element = OrderedDictionary < String , ArraySlice < Substring ? > > . Element
224+ public typealias Index = OrderedDictionary < String , ArraySlice < Substring ? > > . Index
224225
225226 @inlinable
226227 public var startIndex : Index {
227- self . fields. startIndex
228+ self . fields. elements . startIndex
228229 }
229230
230231 @inlinable
231232 public var endIndex : Index {
232- self . fields. endIndex
233+ self . fields. elements . endIndex
233234 }
234235
235236 @inlinable
236237 public subscript( position: Index ) -> Element {
237- self . fields [ position]
238+ self . fields. elements [ position]
238239 }
239240
240241 @inlinable
241242 public func index( after i: Index ) -> Index {
242- self . fields. index ( after: i)
243+ self . fields. elements . index ( after: i)
243244 }
244245}
245246
@@ -253,11 +254,7 @@ extension URLRequestData.Fields: ExpressibleByDictionaryLiteral {
253254extension URLRequestData . Fields : Equatable {
254255 @inlinable
255256 public static func == ( lhs: Self , rhs: Self ) -> Bool {
256- guard lhs. count == rhs. count else { return false }
257- for key in lhs. fields. keys {
258- guard lhs [ key] == rhs [ key] else { return false }
259- }
260- return true
257+ lhs. fields == rhs. fields
261258 }
262259}
263260
0 commit comments