netguru / ResponseDetective

Sherlock Holmes of the networking layer. :male_detective:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Some Requests are getting cancelled when Response Detective is enabled

ran-helfer opened this issue · comments

I am using a POST network call which does get cancelled for some unknown reason.

When i am not enabling responseDetective, i do get a response with code 200.

I am using pure URLSession. Not using any external libraries for the request.

When responseDetective is active the request is getting cancelled and on console log i do see:

 [Info] (NetworkLogger, output(requestRepresentation:), 23): [Network] Request id EFF99D2A-7E69-414D-B6C9-9C1D993D4BAD (POST) api/v0/somePath/other
 API MISUSE: NSURLSession delegate RDTURLProtocol: <RDTURLProtocol: 0x6000019f2c10> (0x6000019f2c10)
 API MISUSE: task:willPerformHTTPRedirection:newRequest:completionHandler: completion handler not called
 [Error] (NetworkLogger, output(errorRepresentation:), 47): [Network] Error id EFF99D2A-7E69-414D-B6C9-9C1D993D4BAD domain: NSURLErrorDomain code: -999 reason: cancelado
[Info] (NetworkLogger, output(requestRepresentation:), 23): [Network] Request id 82292D2C-05B7-4950-AC17-9B88516ABA1F (POST) api/v0/somePath/other/xxxxx

ok - seem like ResponseDetective is not calling completion at:

/// - SeeAlso: URLSessionTaskDelegate.urlSession(_:task:willPerformHTTPRedirection:newRequest:completionHandler:)
	internal func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void) {
		client?.urlProtocol(self, wasRedirectedTo: request, redirectResponse: response)
}

So all we need to do is to add a completionHandler() call to this method implementation