RequestTests.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. // RequestTests.swift
  2. //
  3. // Copyright (c) 2014-2015 Alamofire Software Foundation (http://alamofire.org)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. import Alamofire
  23. import Foundation
  24. import XCTest
  25. class RequestInitializationTestCase: BaseTestCase {
  26. func testRequestClassMethodWithMethodAndURL() {
  27. // Given
  28. let URLString = "https://httpbin.org/"
  29. // When
  30. let request = Alamofire.request(.GET, URLString)
  31. // Then
  32. XCTAssertNotNil(request.request, "request URL request should not be nil")
  33. XCTAssertEqual(request.request?.HTTPMethod ?? "", "GET", "request HTTP method should match expected value")
  34. XCTAssertEqual(request.request?.URLString ?? "", URLString, "request URL string should be equal")
  35. XCTAssertNil(request.response, "request response should be nil")
  36. }
  37. func testRequestClassMethodWithMethodAndURLAndParameters() {
  38. // Given
  39. let URLString = "https://httpbin.org/get"
  40. // When
  41. let request = Alamofire.request(.GET, URLString, parameters: ["foo": "bar"])
  42. // Then
  43. XCTAssertNotNil(request.request, "request URL request should not be nil")
  44. XCTAssertEqual(request.request?.HTTPMethod ?? "", "GET", "request HTTP method should match expected value")
  45. XCTAssertNotEqual(request.request?.URLString ?? "", URLString, "request URL string should be equal")
  46. XCTAssertEqual(request.request?.URL?.query ?? "", "foo=bar", "query is incorrect")
  47. XCTAssertNil(request.response, "request response should be nil")
  48. }
  49. func testRequestClassMethodWithMethodURLParametersAndHeaders() {
  50. // Given
  51. let URLString = "https://httpbin.org/get"
  52. let headers = ["Authorization": "123456"]
  53. // When
  54. let request = Alamofire.request(.GET, URLString, parameters: ["foo": "bar"], headers: headers)
  55. // Then
  56. XCTAssertNotNil(request.request, "request should not be nil")
  57. XCTAssertEqual(request.request?.HTTPMethod ?? "", "GET", "request HTTP method should match expected value")
  58. XCTAssertNotEqual(request.request?.URLString ?? "", URLString, "request URL string should be equal")
  59. XCTAssertEqual(request.request?.URL?.query ?? "", "foo=bar", "query is incorrect")
  60. let authorizationHeader = request.request?.valueForHTTPHeaderField("Authorization") ?? ""
  61. XCTAssertEqual(authorizationHeader, "123456", "Authorization header is incorrect")
  62. XCTAssertNil(request.response, "response should be nil")
  63. }
  64. }
  65. // MARK: -
  66. class RequestResponseTestCase: BaseTestCase {
  67. func testRequestResponse() {
  68. // Given
  69. let URLString = "https://httpbin.org/get"
  70. let expectation = expectationWithDescription("GET request should succeed: \(URLString)")
  71. var request: NSURLRequest?
  72. var response: NSHTTPURLResponse?
  73. var data: NSData?
  74. var error: NSError?
  75. // When
  76. Alamofire.request(.GET, URLString, parameters: ["foo": "bar"])
  77. .response { responseRequest, responseResponse, responseData, responseError in
  78. request = responseRequest
  79. response = responseResponse
  80. data = responseData
  81. error = responseError
  82. expectation.fulfill()
  83. }
  84. waitForExpectationsWithTimeout(timeout, handler: nil)
  85. // Then
  86. XCTAssertNotNil(request, "request should not be nil")
  87. XCTAssertNotNil(response, "response should not be nil")
  88. XCTAssertNotNil(data, "data should not be nil")
  89. XCTAssertNil(error, "error should be nil")
  90. }
  91. func testRequestResponseWithProgress() {
  92. // Given
  93. let randomBytes = 4 * 1024 * 1024
  94. let URLString = "https://httpbin.org/bytes/\(randomBytes)"
  95. let expectation = expectationWithDescription("Bytes download progress should be reported: \(URLString)")
  96. var byteValues: [(bytes: Int64, totalBytes: Int64, totalBytesExpected: Int64)] = []
  97. var progressValues: [(completedUnitCount: Int64, totalUnitCount: Int64)] = []
  98. var responseRequest: NSURLRequest?
  99. var responseResponse: NSHTTPURLResponse?
  100. var responseData: NSData?
  101. var responseError: ErrorType?
  102. // When
  103. let request = Alamofire.request(.GET, URLString)
  104. request.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
  105. let bytes = (bytes: bytesRead, totalBytes: totalBytesRead, totalBytesExpected: totalBytesExpectedToRead)
  106. byteValues.append(bytes)
  107. let progress = (
  108. completedUnitCount: request.progress.completedUnitCount,
  109. totalUnitCount: request.progress.totalUnitCount
  110. )
  111. progressValues.append(progress)
  112. }
  113. request.response { request, response, data, error in
  114. responseRequest = request
  115. responseResponse = response
  116. responseData = data
  117. responseError = error
  118. expectation.fulfill()
  119. }
  120. waitForExpectationsWithTimeout(timeout, handler: nil)
  121. // Then
  122. XCTAssertNotNil(responseRequest, "response request should not be nil")
  123. XCTAssertNotNil(responseResponse, "response response should not be nil")
  124. XCTAssertNotNil(responseData, "response data should not be nil")
  125. XCTAssertNil(responseError, "response error should be nil")
  126. XCTAssertEqual(byteValues.count, progressValues.count, "byteValues count should equal progressValues count")
  127. if byteValues.count == progressValues.count {
  128. for index in 0..<byteValues.count {
  129. let byteValue = byteValues[index]
  130. let progressValue = progressValues[index]
  131. XCTAssertGreaterThan(byteValue.bytes, 0, "reported bytes should always be greater than 0")
  132. XCTAssertEqual(
  133. byteValue.totalBytes,
  134. progressValue.completedUnitCount,
  135. "total bytes should be equal to completed unit count"
  136. )
  137. XCTAssertEqual(
  138. byteValue.totalBytesExpected,
  139. progressValue.totalUnitCount,
  140. "total bytes expected should be equal to total unit count"
  141. )
  142. }
  143. }
  144. if let
  145. lastByteValue = byteValues.last,
  146. lastProgressValue = progressValues.last
  147. {
  148. let byteValueFractionalCompletion = Double(lastByteValue.totalBytes) / Double(lastByteValue.totalBytesExpected)
  149. let progressValueFractionalCompletion = Double(lastProgressValue.0) / Double(lastProgressValue.1)
  150. XCTAssertEqual(byteValueFractionalCompletion, 1.0, "byte value fractional completion should equal 1.0")
  151. XCTAssertEqual(progressValueFractionalCompletion, 1.0, "progress value fractional completion should equal 1.0")
  152. } else {
  153. XCTFail("last item in bytesValues and progressValues should not be nil")
  154. }
  155. }
  156. func testRequestResponseWithStream() {
  157. // Given
  158. let randomBytes = 4 * 1024 * 1024
  159. let URLString = "https://httpbin.org/bytes/\(randomBytes)"
  160. let expectation = expectationWithDescription("Bytes download progress should be reported: \(URLString)")
  161. var byteValues: [(bytes: Int64, totalBytes: Int64, totalBytesExpected: Int64)] = []
  162. var progressValues: [(completedUnitCount: Int64, totalUnitCount: Int64)] = []
  163. var accumulatedData = [NSData]()
  164. var responseRequest: NSURLRequest?
  165. var responseResponse: NSHTTPURLResponse?
  166. var responseData: NSData?
  167. var responseError: ErrorType?
  168. // When
  169. let request = Alamofire.request(.GET, URLString)
  170. request.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
  171. let bytes = (bytes: bytesRead, totalBytes: totalBytesRead, totalBytesExpected: totalBytesExpectedToRead)
  172. byteValues.append(bytes)
  173. let progress = (
  174. completedUnitCount: request.progress.completedUnitCount,
  175. totalUnitCount: request.progress.totalUnitCount
  176. )
  177. progressValues.append(progress)
  178. }
  179. request.stream { accumulatedData.append($0) }
  180. request.response { request, response, data, error in
  181. responseRequest = request
  182. responseResponse = response
  183. responseData = data
  184. responseError = error
  185. expectation.fulfill()
  186. }
  187. waitForExpectationsWithTimeout(timeout, handler: nil)
  188. // Then
  189. XCTAssertNotNil(responseRequest, "response request should not be nil")
  190. XCTAssertNotNil(responseResponse, "response response should not be nil")
  191. XCTAssertNil(responseData, "response data should be nil")
  192. XCTAssertNil(responseError, "response error should be nil")
  193. XCTAssertGreaterThanOrEqual(accumulatedData.count, 1, "accumulated data should have one or more parts")
  194. XCTAssertEqual(byteValues.count, progressValues.count, "byteValues count should equal progressValues count")
  195. if byteValues.count == progressValues.count {
  196. for index in 0..<byteValues.count {
  197. let byteValue = byteValues[index]
  198. let progressValue = progressValues[index]
  199. XCTAssertGreaterThan(byteValue.bytes, 0, "reported bytes should always be greater than 0")
  200. XCTAssertEqual(
  201. byteValue.totalBytes,
  202. progressValue.completedUnitCount,
  203. "total bytes should be equal to completed unit count"
  204. )
  205. XCTAssertEqual(
  206. byteValue.totalBytesExpected,
  207. progressValue.totalUnitCount,
  208. "total bytes expected should be equal to total unit count"
  209. )
  210. }
  211. }
  212. if let
  213. lastByteValue = byteValues.last,
  214. lastProgressValue = progressValues.last
  215. {
  216. let byteValueFractionalCompletion = Double(lastByteValue.totalBytes) / Double(lastByteValue.totalBytesExpected)
  217. let progressValueFractionalCompletion = Double(lastProgressValue.0) / Double(lastProgressValue.1)
  218. XCTAssertEqual(byteValueFractionalCompletion, 1.0, "byte value fractional completion should equal 1.0")
  219. XCTAssertEqual(
  220. progressValueFractionalCompletion,
  221. 1.0,
  222. "progress value fractional completion should equal 1.0"
  223. )
  224. XCTAssertEqual(
  225. accumulatedData.reduce(Int64(0)) { $0 + $1.length },
  226. lastByteValue.totalBytes,
  227. "accumulated data length should match byte count"
  228. )
  229. } else {
  230. XCTFail("last item in bytesValues and progressValues should not be nil")
  231. }
  232. }
  233. func testPOSTRequestWithUnicodeParameters() {
  234. // Given
  235. let URLString = "https://httpbin.org/post"
  236. let parameters = [
  237. "french": "français",
  238. "japanese": "日本語",
  239. "arabic": "العربية",
  240. "emoji": "😃"
  241. ]
  242. let expectation = expectationWithDescription("request should succeed")
  243. var response: Response<AnyObject, NSError>?
  244. // When
  245. Alamofire.request(.POST, URLString, parameters: parameters)
  246. .responseJSON { closureResponse in
  247. response = closureResponse
  248. expectation.fulfill()
  249. }
  250. waitForExpectationsWithTimeout(timeout, handler: nil)
  251. // Then
  252. if let response = response {
  253. XCTAssertNotNil(response.request, "request should not be nil")
  254. XCTAssertNotNil(response.response, "response should not be nil")
  255. XCTAssertNotNil(response.data, "data should not be nil")
  256. if let
  257. JSON = response.result.value as? [String: AnyObject],
  258. form = JSON["form"] as? [String: String]
  259. {
  260. XCTAssertEqual(form["french"], parameters["french"], "french parameter value should match form value")
  261. XCTAssertEqual(form["japanese"], parameters["japanese"], "japanese parameter value should match form value")
  262. XCTAssertEqual(form["arabic"], parameters["arabic"], "arabic parameter value should match form value")
  263. XCTAssertEqual(form["emoji"], parameters["emoji"], "emoji parameter value should match form value")
  264. } else {
  265. XCTFail("form parameter in JSON should not be nil")
  266. }
  267. } else {
  268. XCTFail("response should not be nil")
  269. }
  270. }
  271. func testPOSTRequestWithBase64EncodedImages() {
  272. // Given
  273. let URLString = "https://httpbin.org/post"
  274. let pngBase64EncodedString: String = {
  275. let URL = URLForResource("unicorn", withExtension: "png")
  276. let data = NSData(contentsOfURL: URL)!
  277. return data.base64EncodedStringWithOptions(.Encoding64CharacterLineLength)
  278. }()
  279. let jpegBase64EncodedString: String = {
  280. let URL = URLForResource("rainbow", withExtension: "jpg")
  281. let data = NSData(contentsOfURL: URL)!
  282. return data.base64EncodedStringWithOptions(.Encoding64CharacterLineLength)
  283. }()
  284. let parameters = [
  285. "email": "user@alamofire.org",
  286. "png_image": pngBase64EncodedString,
  287. "jpeg_image": jpegBase64EncodedString
  288. ]
  289. let expectation = expectationWithDescription("request should succeed")
  290. var response: Response<AnyObject, NSError>?
  291. // When
  292. Alamofire.request(.POST, URLString, parameters: parameters)
  293. .responseJSON { closureResponse in
  294. response = closureResponse
  295. expectation.fulfill()
  296. }
  297. waitForExpectationsWithTimeout(timeout, handler: nil)
  298. // Then
  299. if let response = response {
  300. XCTAssertNotNil(response.request, "request should not be nil")
  301. XCTAssertNotNil(response.response, "response should not be nil")
  302. XCTAssertNotNil(response.data, "data should not be nil")
  303. XCTAssertTrue(response.result.isSuccess, "result should be success")
  304. if let
  305. JSON = response.result.value as? [String: AnyObject],
  306. form = JSON["form"] as? [String: String]
  307. {
  308. XCTAssertEqual(form["email"], parameters["email"], "email parameter value should match form value")
  309. XCTAssertEqual(form["png_image"], parameters["png_image"], "png_image parameter value should match form value")
  310. XCTAssertEqual(form["jpeg_image"], parameters["jpeg_image"], "jpeg_image parameter value should match form value")
  311. } else {
  312. XCTFail("form parameter in JSON should not be nil")
  313. }
  314. } else {
  315. XCTFail("response should not be nil")
  316. }
  317. }
  318. }
  319. // MARK: -
  320. extension Request {
  321. private func preValidate(operation: Void -> Void) -> Self {
  322. delegate.queue.addOperationWithBlock {
  323. operation()
  324. }
  325. return self
  326. }
  327. private func postValidate(operation: Void -> Void) -> Self {
  328. delegate.queue.addOperationWithBlock {
  329. operation()
  330. }
  331. return self
  332. }
  333. }
  334. // MARK: -
  335. class RequestExtensionTestCase: BaseTestCase {
  336. func testThatRequestExtensionHasAccessToTaskDelegateQueue() {
  337. // Given
  338. let URLString = "https://httpbin.org/get"
  339. let expectation = expectationWithDescription("GET request should succeed: \(URLString)")
  340. var responses: [String] = []
  341. // When
  342. Alamofire.request(.GET, URLString)
  343. .preValidate {
  344. responses.append("preValidate")
  345. }
  346. .validate()
  347. .postValidate {
  348. responses.append("postValidate")
  349. }
  350. .response { _, _, _, _ in
  351. responses.append("response")
  352. expectation.fulfill()
  353. }
  354. waitForExpectationsWithTimeout(timeout, handler: nil)
  355. // Then
  356. if responses.count == 3 {
  357. XCTAssertEqual(responses[0], "preValidate", "response at index 0 should be preValidate")
  358. XCTAssertEqual(responses[1], "postValidate", "response at index 1 should be postValidate")
  359. XCTAssertEqual(responses[2], "response", "response at index 2 should be response")
  360. } else {
  361. XCTFail("responses count should be equal to 3")
  362. }
  363. }
  364. }
  365. // MARK: -
  366. class RequestDescriptionTestCase: BaseTestCase {
  367. func testRequestDescription() {
  368. // Given
  369. let URLString = "https://httpbin.org/get"
  370. let request = Alamofire.request(.GET, URLString)
  371. let initialRequestDescription = request.description
  372. let expectation = expectationWithDescription("Request description should update: \(URLString)")
  373. var finalRequestDescription: String?
  374. var response: NSHTTPURLResponse?
  375. // When
  376. request.response { _, responseResponse, _, _ in
  377. finalRequestDescription = request.description
  378. response = responseResponse
  379. expectation.fulfill()
  380. }
  381. waitForExpectationsWithTimeout(timeout, handler: nil)
  382. // Then
  383. XCTAssertEqual(initialRequestDescription, "GET https://httpbin.org/get", "incorrect request description")
  384. XCTAssertEqual(
  385. finalRequestDescription ?? "",
  386. "GET https://httpbin.org/get (\(response?.statusCode ?? -1))",
  387. "incorrect request description"
  388. )
  389. }
  390. }
  391. // MARK: -
  392. class RequestDebugDescriptionTestCase: BaseTestCase {
  393. // MARK: Properties
  394. let manager: Manager = {
  395. let manager = Manager(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())
  396. manager.startRequestsImmediately = false
  397. return manager
  398. }()
  399. let managerDisallowingCookies: Manager = {
  400. let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
  401. configuration.HTTPShouldSetCookies = false
  402. let manager = Manager(configuration: configuration)
  403. manager.startRequestsImmediately = false
  404. return manager
  405. }()
  406. // MARK: Tests
  407. func testGETRequestDebugDescription() {
  408. // Given
  409. let URLString = "https://httpbin.org/get"
  410. // When
  411. let request = manager.request(.GET, URLString)
  412. let components = cURLCommandComponents(request)
  413. // Then
  414. XCTAssertEqual(components[0..<3], ["$", "curl", "-i"], "components should be equal")
  415. XCTAssertFalse(components.contains("-X"), "command should not contain explicit -X flag")
  416. XCTAssertEqual(components.last ?? "", "\"\(URLString)\"", "URL component should be equal")
  417. }
  418. func testPOSTRequestDebugDescription() {
  419. // Given
  420. let URLString = "https://httpbin.org/post"
  421. // When
  422. let request = manager.request(.POST, URLString)
  423. let components = cURLCommandComponents(request)
  424. // Then
  425. XCTAssertEqual(components[0..<3], ["$", "curl", "-i"], "components should be equal")
  426. XCTAssertEqual(components[3..<5], ["-X", "POST"], "command should contain explicit -X flag")
  427. XCTAssertEqual(components.last ?? "", "\"\(URLString)\"", "URL component should be equal")
  428. }
  429. func testPOSTRequestWithJSONParametersDebugDescription() {
  430. // Given
  431. let URLString = "https://httpbin.org/post"
  432. // When
  433. let request = manager.request(.POST, URLString, parameters: ["foo": "bar"], encoding: .JSON)
  434. let components = cURLCommandComponents(request)
  435. // Then
  436. XCTAssertEqual(components[0..<3], ["$", "curl", "-i"], "components should be equal")
  437. XCTAssertEqual(components[3..<5], ["-X", "POST"], "command should contain explicit -X flag")
  438. XCTAssertTrue(
  439. request.debugDescription.rangeOfString("-H \"Content-Type: application/json\"") != nil,
  440. "command should contain 'application/json' Content-Type"
  441. )
  442. XCTAssertTrue(
  443. request.debugDescription.rangeOfString("-d \"{\\\"foo\\\":\\\"bar\\\"}\"") != nil,
  444. "command data should contain JSON encoded parameters"
  445. )
  446. XCTAssertEqual(components.last ?? "", "\"\(URLString)\"", "URL component should be equal")
  447. }
  448. func testPOSTRequestWithCookieDebugDescription() {
  449. // Given
  450. let URLString = "https://httpbin.org/post"
  451. let properties = [
  452. NSHTTPCookieDomain: "httpbin.org",
  453. NSHTTPCookiePath: "/post",
  454. NSHTTPCookieName: "foo",
  455. NSHTTPCookieValue: "bar",
  456. ]
  457. let cookie = NSHTTPCookie(properties: properties)!
  458. manager.session.configuration.HTTPCookieStorage?.setCookie(cookie)
  459. // When
  460. let request = manager.request(.POST, URLString)
  461. let components = cURLCommandComponents(request)
  462. // Then
  463. XCTAssertEqual(components[0..<3], ["$", "curl", "-i"], "components should be equal")
  464. XCTAssertEqual(components[3..<5], ["-X", "POST"], "command should contain explicit -X flag")
  465. XCTAssertEqual(components.last ?? "", "\"\(URLString)\"", "URL component should be equal")
  466. XCTAssertEqual(components[5..<6], ["-b"], "command should contain -b flag")
  467. }
  468. func testPOSTRequestWithCookiesDisabledDebugDescription() {
  469. // Given
  470. let URLString = "https://httpbin.org/post"
  471. let properties = [
  472. NSHTTPCookieDomain: "httpbin.org",
  473. NSHTTPCookiePath: "/post",
  474. NSHTTPCookieName: "foo",
  475. NSHTTPCookieValue: "bar",
  476. ]
  477. let cookie = NSHTTPCookie(properties: properties)!
  478. managerDisallowingCookies.session.configuration.HTTPCookieStorage?.setCookie(cookie)
  479. // When
  480. let request = managerDisallowingCookies.request(.POST, URLString)
  481. let components = cURLCommandComponents(request)
  482. // Then
  483. let cookieComponents = components.filter { $0 == "-b" }
  484. XCTAssertTrue(cookieComponents.isEmpty, "command should not contain -b flag")
  485. }
  486. func testThatRequestWithInvalidURLDebugDescription() {
  487. // Given
  488. let URLString = "invalid_url"
  489. // When
  490. let request = manager.request(.GET, URLString)
  491. let debugDescription = request.debugDescription
  492. // Then
  493. XCTAssertNotNil(debugDescription, "debugDescription should not crash")
  494. }
  495. // MARK: Test Helper Methods
  496. private func cURLCommandComponents(request: Request) -> [String] {
  497. let whitespaceCharacterSet = NSCharacterSet.whitespaceAndNewlineCharacterSet()
  498. return request.debugDescription.componentsSeparatedByCharactersInSet(whitespaceCharacterSet)
  499. .filter { $0 != "" && $0 != "\\" }
  500. }
  501. }