Hi there.
I'm sending you patch as attachment. It resolves issue with saving
cookies when 401 error occurs. I'm investigating need of modification
wget behaviour in case of another errors/responses, but it's probably
bad idea - for example for 50X codes.
As you can see, piece of code responsible for cookie handling executed
after proper authorization was moved up - when wget catches 401 it's
executed. I tested it on my webserver and it seems to work nice.
What do you think about proposed resolution?