public HostCredentials onAuthorizationAsked(final HttpGet req) throws OPDSException {
final String host = req.getURI().getHost();
HostCredentials cred = credentials.get(host);
if (cred == null) {
cred = new HostCredentials(host, "", "");
cred.setState(State.AUTH_ASKED);
credentials.put(host, cred);
throw new AuthorizationRequiredException(host, "Basic");
}
if (req.getFirstHeader("Authorization") != null) {
cred.setState(State.AUTH_SENT, State.AUTH_FAILED);
}
final State state = cred.getState();
if (state == State.AUTH_ASKED || state == State.AUTH_FAILED) {
throw new AuthorizationRequiredException(host, "Basic");
}
cred.setState(State.AUTH_SENT);
return cred;
}