Skip to content

Commit 7a316d6

Browse files
author
Adam Debono
committed
added headers parameter to request protocol
1 parent 37d076c commit 7a316d6

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

NetworkMapper.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "NetworkMapper"
3-
s.version = "0.1.0"
3+
s.version = "0.1.1"
44
s.summary = "A framework to map JSON responses to swift objects"
55
s.homepage = "https://github.com/adamdebono/NetworkMapper"
66
s.license = { :type => "MIT", :file => "LICENSE" }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A framework to map JSON responses to swift objects, based on
88

99
### Cocoapods
1010
```ruby
11-
pod 'NetworkMapper', '~> 0.0.3'
11+
pod 'NetworkMapper', '~> 0.1.1'
1212
```
1313

1414
## Usage

Source/NetworkRequest.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
4448
public 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

Comments
 (0)