Skip to content

Commit

Permalink
avoid concurrent read from httpBodyStream
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanSuciu authored and Ștefan Suciu committed Mar 28, 2018
1 parent eb74da9 commit 5aadaa0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
9 changes: 8 additions & 1 deletion netfox/Core/NFXHTTPModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,16 @@ fileprivate func < <T : Comparable>(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()
Expand Down
4 changes: 0 additions & 4 deletions netfox/Core/NFXHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
3 changes: 3 additions & 0 deletions netfox/Core/NFXProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5aadaa0

Please sign in to comment.