Hmm. For digest authentication CFNetwork handles building the authorization header, so I fear it may be outside of our control.
From this page:
"Safari and Chrome encode to ISO-8859-1, and fail to send the authorization header at all when a non-8859-1 character is used."
and
"HTTP Digest authentication is no solution for this problem, either. It suffers from the same problem of the client being unable to tell the server what character set it's using and the server being unable to correctly assume what the client used."
It sounds like it's not safe to use unicode for basic or digest authentication credentials. It may be that other clients/apis you've tested with do use utf-8, and your server is assuming utf-8, but CFNetwork is using iso-8859-1, so it breaks.
Perhaps someone else can make a suggestion, otherwise, it might be better to use a different approach (eg POST the credentials and use a session cookie).
Best,
Ben
Given it should be impossible for CFNetwork to tell you've given it
UTF-8 when it was expecting iso-8859-1, you could try something like this:
NSString *username = @"flibble";
const char *utf8String = [username UTF8String];
NSString *usernameUtf8 = [NSString stringWithCString utf8String
encoding:NSISOLatin1StringEncoding];
Completely untested, but I can't think of a reason it wouldn't work.
Essentially we'd be giving a UTF8 string to CFNetwork, but telling it
that it's Latin1 - so when it converts it back to Latin1 to send to the
server it'll end up with UTF8. This only works because they're 8 bit
encodings, and Latin1 (essentially[*]) defines all 256 possible
characters to be valid, meaning that UTF8 is "valid" Latin1.
Joseph
[*] There's complications as Latin1 has been extended by Microsoft and
other people to add extra characters, so technically "pure" "as per
standard" ISO-8559-1 doesn't define some of the 256 characters.
That's a neat solution! :)
Glad you got it working anyhow.
Best
Ben