Last active
August 22, 2016 09:06
-
-
Save tomaskraina/d644af49e4968de85e34 to your computer and use it in GitHub Desktop.
extension NSURLRequest: DebugPrintable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSURLRequestExtension.swift | |
// | |
// Source: https://gist.github.com/tomaskraina/d644af49e4968de85e34 | |
// | |
// Created by Tom Kraina on 21/04/2015. | |
// Copyright (c) 2015 Tom Kraina. All rights reserved. | |
// | |
import Foundation | |
// Inspired by: https://github.com/Blackjacx/NSURLRequest-SHLogging, | |
extension NSURLRequest { | |
public func extendedDescription() -> String { | |
var result = "<\(NSStringFromClass(self.dynamicType)): " + String(format: "%p", self) | |
result += "; HTTPMethod=\(HTTPMethod ?? "nil"); URL=\(URL); timeoutInterval=\(String(format: "%.1fs", timeoutInterval))> {" | |
// Add header fields. | |
if let headers = allHTTPHeaderFields { | |
result += "\nallHTTPHeaderFields {" | |
for (key, value) in headers { | |
result += "\n\t\(key) : '\(value)'" | |
} | |
result += "\n}" | |
} | |
if let body = HTTPBody { | |
result += "\nHTTPBody {\n \(String(data: body, encoding: NSASCIIStringEncoding) ?? "")\n}" | |
} | |
return result + "\n}" | |
} | |
public override var debugDescription: String { | |
return extendedDescription() | |
} | |
public override var description: String { | |
return extendedDescription() | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If printed out, it displays something similar to the following: