diff --git a/netfox/Core/NFXHTTPModel.swift b/netfox/Core/NFXHTTPModel.swift index 85049769..b225e3f0 100755 --- a/netfox/Core/NFXHTTPModel.swift +++ b/netfox/Core/NFXHTTPModel.swift @@ -55,9 +55,16 @@ fileprivate func < (lhs: T?, rhs: T?) -> Bool { self.requestTimeout = request.getNFXTimeout() self.requestHeaders = request.getNFXHeaders() self.requestType = requestHeaders?["Content-Type"] as! String? + } + + func saveRequestBody(_ request: URLRequest) + { saveRequestBodyData(request.getNFXBody()) + } + + func logRequest(_ request: URLRequest) + { formattedRequestLogEntry().appendToFile(filePath: NFXPath.SessionLog) - } func saveErrorResponse() diff --git a/netfox/Core/NFXHelper.swift b/netfox/Core/NFXHelper.swift index cb8289c9..4de256d4 100644 --- a/netfox/Core/NFXHelper.swift +++ b/netfox/Core/NFXHelper.swift @@ -170,10 +170,6 @@ extension URLRequest func getNFXBody() -> Data { - guard let contentType: String = getNFXHeaders()["Content-Type"] as? String, !contentType.contains("multipart/form-data") else { - return httpBody ?? URLProtocol.property(forKey: "NFXBodyData", in: self) as? Data ?? Data() - } - return httpBodyStream?.readfully() ?? URLProtocol.property(forKey: "NFXBodyData", in: self) as? Data ?? Data() } } diff --git a/netfox/Core/NFXProtocol.swift b/netfox/Core/NFXProtocol.swift index f1c99bbf..fbe3d452 100755 --- a/netfox/Core/NFXProtocol.swift +++ b/netfox/Core/NFXProtocol.swift @@ -69,6 +69,9 @@ open class NFXProtocol: URLProtocol session!.dataTask(with: req as URLRequest, completionHandler: {data, response, error in + self.model?.saveRequestBody(req as URLRequest) + self.model?.logRequest(req as URLRequest) + if let error = error { self.model?.saveErrorResponse() self.loaded()