|
|
@@ -87,10 +87,16 @@ extension NSURLRequest: URLRequestConvertible {
|
|
|
|
|
|
// MARK: - Convenience
|
|
|
|
|
|
-func URLRequest(method: Method, URL: URLStringConvertible) -> NSMutableURLRequest {
|
|
|
- let mutableURLRequest = NSMutableURLRequest(URL: NSURL(string: URL.URLString)!)
|
|
|
+func URLRequest(method: Method, URLString: URLStringConvertible, headers: [String: String]? = nil) -> NSMutableURLRequest {
|
|
|
+ let mutableURLRequest = NSMutableURLRequest(URL: NSURL(string: URLString.URLString)!)
|
|
|
mutableURLRequest.HTTPMethod = method.rawValue
|
|
|
|
|
|
+ if let headers = headers {
|
|
|
+ for (headerField, headerValue) in headers {
|
|
|
+ mutableURLRequest.setValue(headerValue, forHTTPHeaderField: headerField)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return mutableURLRequest
|
|
|
}
|
|
|
|
|
|
@@ -103,11 +109,12 @@ func URLRequest(method: Method, URL: URLStringConvertible) -> NSMutableURLReques
|
|
|
:param: URLString The URL string.
|
|
|
:param: parameters The parameters. `nil` by default.
|
|
|
:param: encoding The parameter encoding. `.URL` by default.
|
|
|
+ :param: headers The HTTP headers. `nil` by default.
|
|
|
|
|
|
:returns: The created request.
|
|
|
*/
|
|
|
-public func request(method: Method, URLString: URLStringConvertible, parameters: [String: AnyObject]? = nil, encoding: ParameterEncoding = .URL) -> Request {
|
|
|
- return Manager.sharedInstance.request(method, URLString, parameters: parameters, encoding: encoding)
|
|
|
+public func request(method: Method, URLString: URLStringConvertible, parameters: [String: AnyObject]? = nil, encoding: ParameterEncoding = .URL, headers: [String: String]? = nil) -> Request {
|
|
|
+ return Manager.sharedInstance.request(method, URLString, parameters: parameters, encoding: encoding, headers: headers)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -132,12 +139,13 @@ public func request(URLRequest: URLRequestConvertible) -> Request {
|
|
|
|
|
|
:param: method The HTTP method.
|
|
|
:param: URLString The URL string.
|
|
|
+ :param: headers The HTTP headers. `nil` by default.
|
|
|
:param: file The file to upload.
|
|
|
|
|
|
:returns: The created upload request.
|
|
|
*/
|
|
|
-public func upload(method: Method, URLString: URLStringConvertible, file: NSURL) -> Request {
|
|
|
- return Manager.sharedInstance.upload(method, URLString, file: file)
|
|
|
+public func upload(method: Method, URLString: URLStringConvertible, headers: [String: String]? = nil, file: NSURL) -> Request {
|
|
|
+ return Manager.sharedInstance.upload(method, URLString, headers: headers, file: file)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -159,12 +167,13 @@ public func upload(URLRequest: URLRequestConvertible, file: NSURL) -> Request {
|
|
|
|
|
|
:param: method The HTTP method.
|
|
|
:param: URLString The URL string.
|
|
|
+ :param: headers The HTTP headers. `nil` by default.
|
|
|
:param: data The data to upload.
|
|
|
|
|
|
:returns: The created upload request.
|
|
|
*/
|
|
|
-public func upload(method: Method, URLString: URLStringConvertible, data: NSData) -> Request {
|
|
|
- return Manager.sharedInstance.upload(method, URLString, data: data)
|
|
|
+public func upload(method: Method, URLString: URLStringConvertible, headers: [String: String]? = nil, data: NSData) -> Request {
|
|
|
+ return Manager.sharedInstance.upload(method, URLString, headers: headers, data: data)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -186,12 +195,13 @@ public func upload(URLRequest: URLRequestConvertible, data: NSData) -> Request {
|
|
|
|
|
|
:param: method The HTTP method.
|
|
|
:param: URLString The URL string.
|
|
|
+ :param: headers The HTTP headers. `nil` by default.
|
|
|
:param: stream The stream to upload.
|
|
|
|
|
|
:returns: The created upload request.
|
|
|
*/
|
|
|
-public func upload(method: Method, URLString: URLStringConvertible, stream: NSInputStream) -> Request {
|
|
|
- return Manager.sharedInstance.upload(method, URLString, stream: stream)
|
|
|
+public func upload(method: Method, URLString: URLStringConvertible, headers: [String: String]? = nil, stream: NSInputStream) -> Request {
|
|
|
+ return Manager.sharedInstance.upload(method, URLString, headers: headers, stream: stream)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -213,6 +223,7 @@ public func upload(URLRequest: URLRequestConvertible, stream: NSInputStream) ->
|
|
|
|
|
|
:param: method The HTTP method.
|
|
|
:param: URLString The URL string.
|
|
|
+ :param: headers The HTTP headers. `nil` by default.
|
|
|
:param: multipartFormData The closure used to append body parts to the `MultipartFormData`.
|
|
|
:param: encodingMemoryThreshold The encoding memory threshold in bytes. `MultipartFormDataEncodingMemoryThreshold`
|
|
|
by default.
|
|
|
@@ -221,6 +232,7 @@ public func upload(URLRequest: URLRequestConvertible, stream: NSInputStream) ->
|
|
|
public func upload(
|
|
|
method: Method,
|
|
|
#URLString: URLStringConvertible,
|
|
|
+ headers: [String: String]? = nil,
|
|
|
#multipartFormData: MultipartFormData -> Void,
|
|
|
encodingMemoryThreshold: UInt64 = Manager.MultipartFormDataEncodingMemoryThreshold,
|
|
|
#encodingCompletion: (Manager.MultipartFormDataEncodingResult -> Void)?)
|
|
|
@@ -228,6 +240,7 @@ public func upload(
|
|
|
return Manager.sharedInstance.upload(
|
|
|
method,
|
|
|
URLString,
|
|
|
+ headers: headers,
|
|
|
multipartFormData: multipartFormData,
|
|
|
encodingMemoryThreshold: encodingMemoryThreshold,
|
|
|
encodingCompletion: encodingCompletion
|
|
|
@@ -266,12 +279,13 @@ public func upload(
|
|
|
|
|
|
:param: method The HTTP method.
|
|
|
:param: URLString The URL string.
|
|
|
+ :param: headers The HTTP headers. `nil` by default.
|
|
|
:param: destination The closure used to determine the destination of the downloaded file.
|
|
|
|
|
|
:returns: The created download request.
|
|
|
*/
|
|
|
-public func download(method: Method, URLString: URLStringConvertible, destination: Request.DownloadFileDestination) -> Request {
|
|
|
- return Manager.sharedInstance.download(method, URLString, destination: destination)
|
|
|
+public func download(method: Method, URLString: URLStringConvertible, headers: [String: String]? = nil, destination: Request.DownloadFileDestination) -> Request {
|
|
|
+ return Manager.sharedInstance.download(method, URLString, headers: headers, destination: destination)
|
|
|
}
|
|
|
|
|
|
/**
|