All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.heroku.api.http.UserAgentValueProvider Maven / Gradle / Ivy

There is a newer version: 0.46
Show newest version
package com.heroku.api.http;

import com.heroku.api.Heroku;

/**
 * Provider for User-Agent header values used by HTTP clients.
 *
 * To provide a custom User-Agent value, implement this interface
 * and create a provider-configuration file at
 * META-INF/services/com.heroku.api.http.UserAgentValueProvider
 * containing the fully-qualified name of your provider class.
 * See {@link java.util.ServiceLoader} for details.
 * 
 * To conform to RFC 2616 Section 14.43, consider prepending the value
 * from the {@link DEFAULT} provider with your own user agent.
 *
 * @see java.util.ServiceLoader
 * @see Http.UserAgent
 *
 * @author Ryan Brainard
*/
public interface UserAgentValueProvider {

    String getHeaderValue();
    String getHeaderValue(String customPart);

    class DEFAULT implements UserAgentValueProvider {
        private final String userAgentValuePattern = "heroku.jar/%s (%s) Java/%s (%s)";

        @Override
        public String getHeaderValue() {
            return getHeaderValue("");
        }

        @Override
        public String getHeaderValue(String subComponentUserAgents) {
            return String.format(userAgentValuePattern,
                Heroku.JarProperties.getProperty("heroku.jar.version"),
                subComponentUserAgents,
                System.getProperty("java.version"),
                System.getProperty("java.vendor"));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy