@@ -14,16 +14,18 @@ public struct RequestDetails: URLRequestConvertible {
1414 /// Parameters are encoded and added to the request based on the method of
1515 /// the request
1616 public let parameters : [ String : Any ] ?
17+ /// Any headers (or nil) for the request
18+ public var headers : HTTPHeaders ?
1719
18- public init ( method: HTTPMethod , url: URL , parameters: [ String : Any ] ? = nil ) {
20+ public init ( method: HTTPMethod , url: URL , parameters: [ String : Any ] ? , headers : HTTPHeaders ? ) {
1921 self . method = method
2022 self . url = url
2123 self . parameters = parameters
24+ self . headers = headers
2225 }
2326
2427 public func asURLRequest( ) throws -> URLRequest {
25- var request = URLRequest ( url: self . url)
26- request. httpMethod = self . method. rawValue
28+ var request = try URLRequest ( url: self . url, method: self . method, headers: self . headers)
2729
2830 return try URLEncoding . methodDependent. encode ( request, with: self . parameters)
2931 }
@@ -40,6 +42,8 @@ public protocol NetworkRequest: URLRequestConvertible {
4042 /// Parameters are encoded and added to the request based on the method of
4143 /// the request
4244 var parameters : [ String : Any ] ? { get }
45+ /// Any headers (or nil) for the request
46+ var headers : HTTPHeaders ? { get }
4347}
4448public extension NetworkRequest {
4549 /// Creates a `RequestDetails` object based on the attributes of the
@@ -48,7 +52,8 @@ public extension NetworkRequest {
4852 return RequestDetails (
4953 method: self . method,
5054 url: self . url,
51- parameters: self . parameters
55+ parameters: self . parameters,
56+ headers: self . headers
5257 )
5358 }
5459
0 commit comments