0001 // Alamofire.swift 0002 // 0003 // Copyright (c) 2014–2016 Alamofire Software Foundation (http://alamofire.org/) 0004 // 0005 // Permission is hereby granted, free of charge, to any person obtaining a copy 0006 // of this software and associated documentation files (the "Software"), to deal 0007 // in the Software without restriction, including without limitation the rights 0008 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0009 // copies of the Software, and to permit persons to whom the Software is 0010 // furnished to do so, subject to the following conditions: 0011 // 0012 // The above copyright notice and this permission notice shall be included in 0013 // all copies or substantial portions of the Software. 0014 // 0015 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0016 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0017 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0018 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0019 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0020 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 0021 // THE SOFTWARE. 0022 0023 import Foundation 0024 0025 // MARK: - URLStringConvertible 0026 0027 /** 0028 Types adopting the `URLStringConvertible` protocol can be used to construct URL strings, which are then used to 0029 construct URL requests. 0030 */ 0031 public protocol URLStringConvertible{ 0032 /** 0033 A URL that conforms to RFC 2396. 0034 0035 Methods accepting a `URLStringConvertible` type parameter parse it according to RFCs 1738 and 1808. 0036 0037 See https://tools.ietf.org/html/rfc2396 0038 See https://tools.ietf.org/html/rfc1738 0039 See https://tools.ietf.org/html/rfc1808 0040 */ 0041 var URLString
Alamofire.swift:44 extension String: URLStringConvertible {Alamofire.swift:50 extension NSURL: URLStringConvertible {Alamofire.swift:56 extension NSURLComponents: URLStringConvertible {Alamofire.swift:62 extension NSURLRequest: URLStringConvertible {Alamofire.swift:88 _ URLString: URLStringConvertible,Alamofire.swift:120 _ URLString: URLStringConvertible,Alamofire.swift:164 _ URLString: URLStringConvertible,Alamofire.swift:198 _ URLString: URLStringConvertible,Alamofire.swift:232 _ URLString: URLStringConvertible,Alamofire.swift:267 _ URLString: URLStringConvertible,Alamofire.swift:324 _ URLString: URLStringConvertible,Download.swift:81 _ URLString: URLStringConvertible,Manager.swift:182 _ URLString: URLStringConvertible,Upload.swift:100 _ URLString: URLStringConvertible,Upload.swift:139 _ URLString: URLStringConvertible,Upload.swift:179 _ URLString: URLStringConvertible,Upload.swift:236 _ URLString: URLStringConvertible,: String { get } 0042 } 0043 0044 extension String: URLStringConvertible { 0045 public var URLString: String { 0046 return self 0047 } 0048 } 0049 0050 extension NSURL: URLStringConvertible { 0051 public var URLString
Alamofire.swift:92 let mutableURLRequest = NSMutableURLRequest(URL: NSURL(string: URLString.URLString)!): String { 0052 return absoluteString 0053 } 0054 } 0055 0056 extension NSURLComponents: URLStringConvertible { 0057 public var URLString: String { 0058 return URL!.URLString 0059 } 0060 } 0061 0062 extension NSURLRequest: URLStringConvertible { 0063 public var URLString: String { 0064 return URL!.URLString 0065 } 0066 } 0067 0068 // MARK: - URLRequestConvertible 0069 0070 /** 0071 Types adopting the `URLRequestConvertible` protocol can be used to construct URL requests. 0072 */ 0073 public protocol URLRequestConvertible
Alamofire.swift:58 return URL!.URLStringAlamofire.swift:64 return URL!.URLString{ 0074 /// The URL request. 0075 var URLRequest
Alamofire.swift:78 extension NSURLRequest: URLRequestConvertible {Alamofire.swift:144 public func request(URLRequest: URLRequestConvertible) -> Request {Alamofire.swift:180 public func upload(URLRequest: URLRequestConvertible, file: NSURL) -> Request {Alamofire.swift:214 public func upload(URLRequest: URLRequestConvertible, data: NSData) -> Request {Alamofire.swift:248 public func upload(URLRequest: URLRequestConvertible, stream: NSInputStream) -> Request {Alamofire.swift:293 URLRequest: URLRequestConvertible,Alamofire.swift:349 public func download(URLRequest: URLRequestConvertible, destination: Request.DownloadFileDestination) -> Request {Download.swift:104 public func download(URLRequest: URLRequestConvertible, destination: Request.DownloadFileDestination) -> Request {Manager.swift:202 public func request(URLRequest: URLRequestConvertible) -> Request {ParameterEncoding.swift:67 case Custom((URLRequestConvertible, [String: AnyObject]?) -> (NSMutableURLRequest, NSError?))ParameterEncoding.swift:79 URLRequest: URLRequestConvertible,Upload.swift:82 public func upload(URLRequest: URLRequestConvertible, file: NSURL) -> Request {Upload.swift:121 public func upload(URLRequest: URLRequestConvertible, data: NSData) -> Request {Upload.swift:161 public func upload(URLRequest: URLRequestConvertible, stream: NSInputStream) -> Request {Upload.swift:277 URLRequest: URLRequestConvertible,: NSMutableURLRequest { get } 0076 } 0077 0078 extension NSURLRequest: URLRequestConvertible { 0079 public var URLRequest: NSMutableURLRequest { 0080 return self.mutableCopy() as! NSMutableURLRequest 0081 } 0082 } 0083 0084 // MARK: - Convenience 0085 0086 func URLRequest
Alamofire.swift:145 return Manager.sharedInstance.request(URLRequest.URLRequest)Download.swift:105 return download(.Request(URLRequest.URLRequest), destination: destination)Manager.swift:204 dispatch_sync(queue) { dataTask = self.session.dataTaskWithRequest(URLRequest.URLRequest) }ParameterEncoding.swift:83 var mutableURLRequest = URLRequest.URLRequestUpload.swift:83 return upload(.File(URLRequest.URLRequest, file))Upload.swift:122 return upload(.Data(URLRequest.URLRequest, data))Upload.swift:162 return upload(.Stream(URLRequest.URLRequest, stream))Upload.swift:286 let URLRequestWithContentType = URLRequest.URLRequest( 0087 method: Method, 0088 _ URLString: URLStringConvertible, 0089 headers: [String: String]? = nil) 0090 -> NSMutableURLRequest 0091 { 0092 let mutableURLRequest = NSMutableURLRequest(URL: NSURL(string: URLString.URLString)!) 0093 mutableURLRequest.HTTPMethod = method.rawValue 0094 0095 if let headers = headers { 0096 for (headerField, headerValue) in headers { 0097 mutableURLRequest.setValue(headerValue, forHTTPHeaderField: headerField) 0098 } 0099 } 0100 0101 return mutableURLRequest 0102 } 0103 0104 // MARK: - Request Methods 0105 0106 /** 0107 Creates a request using the shared manager instance for the specified method, URL string, parameters, and 0108 parameter encoding. 0109 0110 - parameter method: The HTTP method. 0111 - parameter URLString: The URL string. 0112 - parameter parameters: The parameters. `nil` by default. 0113 - parameter encoding: The parameter encoding. `.URL` by default. 0114 - parameter headers: The HTTP headers. `nil` by default. 0115 0116 - returns: The created request. 0117 */ 0118 public func request( 0119 method: Method, 0120 _ URLString: URLStringConvertible, 0121 parameters: [String: AnyObject]? = nil, 0122 encoding: ParameterEncoding = .URL, 0123 headers: [String: String]? = nil) 0124 -> Request 0125 { 0126 return Manager.sharedInstance.request( 0127 method, 0128 URLString, 0129 parameters: parameters, 0130 encoding: encoding, 0131 headers: headers 0132 ) 0133 } 0134 0135 /** 0136 Creates a request using the shared manager instance for the specified URL request. 0137 0138 If `startRequestsImmediately` is `true`, the request will have `resume()` called before being returned. 0139 0140 - parameter URLRequest: The URL request 0141 0142 - returns: The created request. 0143 */ 0144 public func request(URLRequest: URLRequestConvertible) -> Request { 0145 return Manager.sharedInstance.request(URLRequest.URLRequest) 0146 } 0147 0148 // MARK: - Upload Methods 0149 0150 // MARK: File 0151 0152 /** 0153 Creates an upload request using the shared manager instance for the specified method, URL string, and file. 0154 0155 - parameter method: The HTTP method. 0156 - parameter URLString: The URL string. 0157 - parameter headers: The HTTP headers. `nil` by default. 0158 - parameter file: The file to upload. 0159 0160 - returns: The created upload request. 0161 */ 0162 public func upload( 0163 method: Method, 0164 _ URLString: URLStringConvertible, 0165 headers: [String: String]? = nil, 0166 file: NSURL) 0167 -> Request 0168 { 0169 return Manager.sharedInstance.upload(method, URLString, headers: headers, file: file) 0170 } 0171 0172 /** 0173 Creates an upload request using the shared manager instance for the specified URL request and file. 0174 0175 - parameter URLRequest: The URL request. 0176 - parameter file: The file to upload. 0177 0178 - returns: The created upload request. 0179 */ 0180 public func upload(URLRequest: URLRequestConvertible, file: NSURL) -> Request { 0181 return Manager.sharedInstance.upload(URLRequest, file: file) 0182 } 0183 0184 // MARK: Data 0185 0186 /** 0187 Creates an upload request using the shared manager instance for the specified method, URL string, and data. 0188 0189 - parameter method: The HTTP method. 0190 - parameter URLString: The URL string. 0191 - parameter headers: The HTTP headers. `nil` by default. 0192 - parameter data: The data to upload. 0193 0194 - returns: The created upload request. 0195 */ 0196 public func upload( 0197 method: Method, 0198 _ URLString: URLStringConvertible, 0199 headers: [String: String]? = nil, 0200 data: NSData) 0201 -> Request 0202 { 0203 return Manager.sharedInstance.upload(method, URLString, headers: headers, data: data) 0204 } 0205 0206 /** 0207 Creates an upload request using the shared manager instance for the specified URL request and data. 0208 0209 - parameter URLRequest: The URL request. 0210 - parameter data: The data to upload. 0211 0212 - returns: The created upload request. 0213 */ 0214 public func upload(URLRequest: URLRequestConvertible, data: NSData) -> Request { 0215 return Manager.sharedInstance.upload(URLRequest, data: data) 0216 } 0217 0218 // MARK: Stream 0219 0220 /** 0221 Creates an upload request using the shared manager instance for the specified method, URL string, and stream. 0222 0223 - parameter method: The HTTP method. 0224 - parameter URLString: The URL string. 0225 - parameter headers: The HTTP headers. `nil` by default. 0226 - parameter stream: The stream to upload. 0227 0228 - returns: The created upload request. 0229 */ 0230 public func upload( 0231 method: Method, 0232 _ URLString: URLStringConvertible, 0233 headers: [String: String]? = nil, 0234 stream: NSInputStream) 0235 -> Request 0236 { 0237 return Manager.sharedInstance.upload(method, URLString, headers: headers, stream: stream) 0238 } 0239 0240 /** 0241 Creates an upload request using the shared manager instance for the specified URL request and stream. 0242 0243 - parameter URLRequest: The URL request. 0244 - parameter stream: The stream to upload. 0245 0246 - returns: The created upload request. 0247 */ 0248 public func upload(URLRequest: URLRequestConvertible, stream: NSInputStream) -> Request { 0249 return Manager.sharedInstance.upload(URLRequest, stream: stream) 0250 } 0251 0252 // MARK: MultipartFormData 0253 0254 /** 0255 Creates an upload request using the shared manager instance for the specified method and URL string. 0256 0257 - parameter method: The HTTP method. 0258 - parameter URLString: The URL string. 0259 - parameter headers: The HTTP headers. `nil` by default. 0260 - parameter multipartFormData: The closure used to append body parts to the `MultipartFormData`. 0261 - parameter encodingMemoryThreshold: The encoding memory threshold in bytes. 0262 `MultipartFormDataEncodingMemoryThreshold` by default. 0263 - parameter encodingCompletion: The closure called when the `MultipartFormData` encoding is complete. 0264 */ 0265 public func upload( 0266 method: Method, 0267 _ URLString: URLStringConvertible, 0268 headers: [String: String]? = nil, 0269 multipartFormData: MultipartFormData -> Void, 0270 encodingMemoryThreshold: UInt64 = Manager.MultipartFormDataEncodingMemoryThreshold, 0271 encodingCompletion: (Manager.MultipartFormDataEncodingResult -> Void)?) 0272 { 0273 return Manager.sharedInstance.upload( 0274 method, 0275 URLString, 0276 headers: headers, 0277 multipartFormData: multipartFormData, 0278 encodingMemoryThreshold: encodingMemoryThreshold, 0279 encodingCompletion: encodingCompletion 0280 ) 0281 } 0282 0283 /** 0284 Creates an upload request using the shared manager instance for the specified method and URL string. 0285 0286 - parameter URLRequest: The URL request. 0287 - parameter multipartFormData: The closure used to append body parts to the `MultipartFormData`. 0288 - parameter encodingMemoryThreshold: The encoding memory threshold in bytes. 0289 `MultipartFormDataEncodingMemoryThreshold` by default. 0290 - parameter encodingCompletion: The closure called when the `MultipartFormData` encoding is complete. 0291 */ 0292 public func upload( 0293 URLRequest: URLRequestConvertible, 0294 multipartFormData: MultipartFormData -> Void, 0295 encodingMemoryThreshold: UInt64 = Manager.MultipartFormDataEncodingMemoryThreshold, 0296 encodingCompletion: (Manager.MultipartFormDataEncodingResult -> Void)?) 0297 { 0298 return Manager.sharedInstance.upload( 0299 URLRequest, 0300 multipartFormData: multipartFormData, 0301 encodingMemoryThreshold: encodingMemoryThreshold, 0302 encodingCompletion: encodingCompletion 0303 ) 0304 } 0305 0306 // MARK: - Download Methods 0307 0308 // MARK: URL Request 0309 0310 /** 0311 Creates a download request using the shared manager instance for the specified method and URL string. 0312 0313 - parameter method: The HTTP method. 0314 - parameter URLString: The URL string. 0315 - parameter parameters: The parameters. `nil` by default. 0316 - parameter encoding: The parameter encoding. `.URL` by default. 0317 - parameter headers: The HTTP headers. `nil` by default. 0318 - parameter destination: The closure used to determine the destination of the downloaded file. 0319 0320 - returns: The created download request. 0321 */ 0322 public func download( 0323 method: Method, 0324 _ URLString: URLStringConvertible, 0325 parameters: [String: AnyObject]? = nil, 0326 encoding: ParameterEncoding = .URL, 0327 headers: [String: String]? = nil, 0328 destination: Request.DownloadFileDestination) 0329 -> Request 0330 { 0331 return Manager.sharedInstance.download( 0332 method, 0333 URLString, 0334 parameters: parameters, 0335 encoding: encoding, 0336 headers: headers, 0337 destination: destination 0338 ) 0339 } 0340 0341 /** 0342 Creates a download request using the shared manager instance for the specified URL request. 0343 0344 - parameter URLRequest: The URL request. 0345 - parameter destination: The closure used to determine the destination of the downloaded file. 0346 0347 - returns: The created download request. 0348 */ 0349 public func download(URLRequest: URLRequestConvertible, destination: Request.DownloadFileDestination) -> Request { 0350 return Manager.sharedInstance.download(URLRequest, destination: destination) 0351 } 0352 0353 // MARK: Resume Data 0354 0355 /** 0356 Creates a request using the shared manager instance for downloading from the resume data produced from a 0357 previous request cancellation. 0358 0359 - parameter resumeData: The resume data. This is an opaque data blob produced by `NSURLSessionDownloadTask` 0360 when a task is cancelled. See `NSURLSession -downloadTaskWithResumeData:` for additional 0361 information. 0362 - parameter destination: The closure used to determine the destination of the downloaded file. 0363 0364 - returns: The created download request. 0365 */ 0366 public func download(resumeData data: NSData, destination: Request.DownloadFileDestination) -> Request { 0367 return Manager.sharedInstance.download(data, destination: destination) 0368 } 0369
Download.swift:88 let mutableURLRequest = URLRequest(method, URLString, headers: headers)Manager.swift:188 let mutableURLRequest = URLRequest(method, URLString, headers: headers)Upload.swift:105 let mutableURLRequest = URLRequest(method, URLString, headers: headers)Upload.swift:144 let mutableURLRequest = URLRequest(method, URLString, headers: headers)Upload.swift:184 let mutableURLRequest = URLRequest(method, URLString, headers: headers)Upload.swift:242 let mutableURLRequest = URLRequest(method, URLString, headers: headers)