@Override
    public void login(final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
        final Credentials credentials = authentication.get();
        if(credentials.isAnonymousLogin()) {
            if(log.isDebugEnabled()) {
                log.debug(String.format("Connect with no credentials to %s", host));
            }
            client.setProviderCredentials(null);
        }
        else {
            if(credentials.getTokens().validate()) {
                if(log.isDebugEnabled()) {
                    log.debug(String.format("Connect with session credentials to %s", host));
                }
                client.setProviderCredentials(new AWSSessionCredentials(
                        credentials.getTokens().getAccessKeyId(), credentials.getTokens().getSecretAccessKey(),
                        credentials.getTokens().getSessionToken()));
            }
            else {
                if(log.isDebugEnabled()) {
                    log.debug(String.format("Connect with basic credentials to %s", host));
                }
                client.setProviderCredentials(new AWSCredentials(credentials.getUsername(), credentials.getPassword()));
            }
        }
        if(host.getCredentials().isPassed()) {
            log.warn(String.format("Skip verifying credentials with previous successful authentication event for %s", this));
            return;
        }
        try {
            final Path home = new DelegatingHomeFeature(new DefaultPathHomeFeature(host)).find();
            final Location.Name location = new S3LocationFeature(S3Session.this, regions).getLocation(home);
            if(log.isDebugEnabled()) {
                log.debug(String.format("Retrieved region %s", location));
            }
            if(!Location.unknown.equals(location)) {
                if(log.isDebugEnabled()) {
                    log.debug(String.format("Set default region to %s determined from %s", location, home));
                }
                //
                host.setProperty("s3.location", location.getIdentifier());
            }
        }
        catch(AccessDeniedException | InteroperabilityException e) {
            log.warn(String.format("Failure %s querying region", e));
            final Path home = new DefaultHomeFinderService(this).find();
            if(log.isDebugEnabled()) {
                log.debug(String.format("Retrieved %s", home));
            }
        }
    }
@Test
    public void testCustomHostname() throws Exception {
        final Host host = new Host(new S3Protocol(), "cyberduck.io", new Credentials(
                PROPERTIES.get("s3.key"), "s"
        ));
        final AtomicBoolean set = new AtomicBoolean();
        final S3Session session = new S3Session(host);
        session.withListener(new TranscriptListener() {
            @Override
            public void log(final Type request, final String message) {
                switch(request) {
                    case request:
                        if(message.contains("Host:")) {
                            assertEquals("Host: cyberduck.io", message);
                            set.set(true);
                        }
                }
            }
        });
        session.open(new DisabledProxyFinder(), new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
        session.login(new DisabledLoginCallback(), new DisabledCancelCallback());
        assertTrue(set.get());
    }