I am trying to create a digest authentication using swift on top of swiftNIO. At the end I get the following error: The operation couldn’t be completed. (NIO.NIOConnectionError error 1.)
Here my way to do:
// in the delegate I create my authorizationHeader
let authorizationHeader = try httpClient.execute(request: digestRequest , delegate: delegate).wait()
then in the main thread i am do the following:
var request = try HTTPClient.Request(url: url, method: .GET)
request.headers.add(name: "Authorization: \(authorizationHeader.description)" , value: "")
print (request.headers.description)
httpClient.execute(request: request).whenComplete { result in
switch result {
case .failure(let error):
print (error.localizedDescription)
case .success(let response):
if response.status == .ok {
print (response.status)
} else {
print ("error in response")
}
}
}
Unfortunately I found no other way to create the header. I had to pass value of "", because the response header has to be (Wikipedia) : "Authorization: " and then the rest. Here an example of my genarated response header: [("Authorization: Digest username=\"myuser\",realm=\"Testserver\",nonce=\"4F4L1eHYktYv6n7LR4s5yyL5uMiVgKSg\",uri=\"http://myurl\",response=\"4bc3cdfc727bec9edebf6a55dac677a7\"", "")]
I am not sure about the error: is it because of my headerresponse or because I am creating a new request from the main thread and not inside my delegate, but httpclient is always the same instance. If it lies on the headerresponse, it seems that there exists no way to write direct the response string into the header using async-http-client.
Thanks Arnold