Open linakis opened 8 years ago
+1
Sadly, we're a little limited due to this bug (http://openradar.appspot.com/15993891), but if anyone has ideas for a workaround, I'm all ears!
I'll be revisiting Timberjack for Swift 3, so I'll do a little digging to see if anything has changed
I've been able to log the post body by reading the HTTPBodyStream property of an NSURLRequest. If you're interested, I can send a PR your way.
private extension NSURLRequest {
func body() -> NSData? {
var data: NSData?
if let body = self.HTTPBody {
data = body
} else if let stream = self.HTTPBodyStream {
stream.open()
data = stream.readData()
stream.close()
}
return data
}
}
private extension NSInputStream {
func readData() -> NSData {
let maxLength = 4096
let data = NSMutableData()
var buffer = Array<UInt8>(count:maxLength, repeatedValue: 0)
var bytesRead = self.read(&buffer, maxLength: maxLength)
while bytesRead > 0 {
data.appendBytes(&buffer, length: bytesRead)
bytesRead = self.read(&buffer, maxLength: maxLength)
}
return data
}
}
Is there any way to include the post body in the logged data?