-
-
Save jayantnd/fe58e74855ffb737932922a54c93ce6b to your computer and use it in GitHub Desktop.
extension NSURLRequest: DebugPrintable
This file contains hidden or 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 | |
// | |
// 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: DebugPrintable { | |
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 " + ((NSString(data: body, encoding: NSASCIIStringEncoding) ?? "") as String) + "}" | |
} | |
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