Class TransportHttp

  • All Implemented Interfaces:
    java.lang.AutoCloseable, PackTransport, WalkTransport

    public class TransportHttp
    extends HttpTransport
    implements WalkTransport, PackTransport
    Transport over HTTP and FTP protocols.

    If the transport is using HTTP and the remote HTTP service is Git-aware (speaks the "smart-http protocol") this client will automatically take advantage of the additional Git-specific HTTP extensions. If the remote service does not support these extensions, the client will degrade to direct file fetching.

    If the remote (server side) repository does not have the specialized Git support, object files are retrieved directly through standard HTTP GET (or binary FTP GET) requests. This make it easy to serve a Git repository through a standard web host provider that does not offer specific support for Git.

    See Also:
    WalkFetchConnection
    • Field Detail

      • LOG

        private static final org.slf4j.Logger LOG
      • SVC_RECEIVE_PACK

        private static final java.lang.String SVC_RECEIVE_PACK
        See Also:
        Constant Field Values
      • currentUri

        private URIish currentUri
        The current URI we're talking to. The inherited (final) field Transport.uri stores the original URI; currentUri may be different after redirects.
      • baseUrl

        private java.net.URL baseUrl
      • objectsUrl

        private java.net.URL objectsUrl
      • proxySelector

        private final java.net.ProxySelector proxySelector
      • useSmartHttp

        private boolean useSmartHttp
      • headers

        private java.util.Map<java.lang.String,​java.lang.String> headers
      • sslVerify

        private boolean sslVerify
      • sslFailure

        private boolean sslFailure
      • cookieFile

        private final NetscapeCookieFile cookieFile
        All stored cookies bound to this repo (independent of the baseUrl)
      • relevantCookies

        private final java.util.Set<java.net.HttpCookie> relevantCookies
        The cookies to be sent with each request to the given baseUrl. Filtered view on top of cookieFile where only cookies which apply to the current url are left. This set needs to be filtered for expired entries each time prior to sending them.
    • Method Detail

      • toURL

        private java.net.URL toURL​(URIish urish)
                            throws java.net.MalformedURLException
        Throws:
        java.net.MalformedURLException
      • setUseSmartHttp

        public void setUseSmartHttp​(boolean on)
        Toggle whether or not smart HTTP transport should be used.

        This flag exists primarily to support backwards compatibility testing within a testing framework, there is no need to modify it in most applications.

        Parameters:
        on - if true (default), smart HTTP is enabled.
      • getConnection

        private FetchConnection getConnection​(HttpConnection c,
                                              java.io.InputStream in,
                                              java.lang.String service)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • toBufferedReader

        private java.io.BufferedReader toBufferedReader​(java.io.InputStream in)
      • close

        public void close()

        Close any resources used by this transport.

        If the remote repository is contacted by a network socket this method must close that network socket, disconnecting the two peers. If the remote repository is actually local (same system) this method must close any open file handles used to read the "remote" repository.

        AutoClosable.close() declares that it throws Exception. Implementers shouldn't throw checked exceptions. This override narrows the signature to prevent them from doing so.

        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in class Transport
      • setAdditionalHeaders

        public void setAdditionalHeaders​(java.util.Map<java.lang.String,​java.lang.String> headers)
        Set additional headers on the HTTP connection
        Parameters:
        headers - a map of name:values that are to be set as headers on the HTTP connection
        Since:
        3.4
      • processResponseCookies

        void processResponseCookies​(HttpConnection conn)
      • extractCookies

        private java.util.List<java.net.HttpCookie> extractCookies​(java.lang.String headerKey,
                                                                   java.util.List<java.lang.String> headerValues)
      • trustInsecureSslConnection

        private boolean trustInsecureSslConnection​(java.lang.Throwable cause)
      • updateSslVerify

        private void updateSslVerify​(StoredConfig config,
                                     boolean value)
      • updateSslVerifyUser

        private void updateSslVerifyUser​(boolean value)
      • isValidRedirect

        private boolean isValidRedirect​(java.net.URL current,
                                        java.lang.String next,
                                        java.lang.String checkFor)
      • httpOpen

        protected HttpConnection httpOpen​(java.lang.String method,
                                          java.net.URL u,
                                          TransportHttp.AcceptEncoding acceptEncoding)
                                   throws java.io.IOException
        Open an HTTP connection.
        Parameters:
        method - HTTP request method
        u - url of the HTTP connection
        acceptEncoding - accept-encoding header option
        Returns:
        the HTTP connection
        Throws:
        java.io.IOException
        Since:
        4.6
      • addHeaders

        static void addHeaders​(HttpConnection conn,
                               java.util.List<java.lang.String> headersToAdd)
        Adds a list of header strings to the connection. Headers are expected to separate keys from values, i.e. "Key: Value". Headers without colon or key are ignored (and logged), as are headers with keys that are not RFC 7230 tokens or with non-ASCII values.
        Parameters:
        conn - The target HttpConnection
        headersToAdd - A list of header strings
      • setCookieHeader

        private void setCookieHeader​(HttpConnection conn)
      • openInputStream

        final java.io.InputStream openInputStream​(HttpConnection conn)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • wrongContentType

        java.io.IOException wrongContentType​(java.lang.String expType,
                                             java.lang.String actType)
      • filterCookies

        private static java.util.Set<java.net.HttpCookie> filterCookies​(NetscapeCookieFile cookieFile,
                                                                        java.net.URL url)
      • filterCookies

        private static java.util.Set<java.net.HttpCookie> filterCookies​(java.util.Set<java.net.HttpCookie> allCookies,
                                                                        java.net.URL url)
        Parameters:
        allCookies - a list of cookies.
        url - the url for which to filter the list of cookies.
        Returns:
        only the cookies from allCookies which are relevant (i.e. are not expired, have a matching domain, have a matching path and have a matching secure attribute)
      • matchesCookieDomain

        static boolean matchesCookieDomain​(java.lang.String host,
                                           java.lang.String cookieDomain)
        The utility method to check whether a host name is in a cookie's domain or not. Similar to HttpCookie.domainMatches(String, String) but implements domain matching rules according to RFC 6265, section 5.1.3 instead of the rules from RFC 2965, section 3.3.1.

        The former rules are also used by libcurl internally.

        The rules are as follows A string matches another domain string if at least one of the following conditions holds:

        • The domain string and the string are identical. (Note that both the domain string and the string will have been canonicalized to lower case at this point.)
        • All of the following conditions hold
          • The domain string is a suffix of the string.
          • The last character of the string that is not included in the domain string is a %x2E (".") character.
          • The string is a host name (i.e., not an IP address).
        Parameters:
        host - the host to compare against the cookieDomain
        cookieDomain - the domain to compare against
        Returns:
        true if they domain-match; false if not
        See Also:
        RFC 6265, section 5.1.3 (Domain Matching), JDK-8206092 : HttpCookie.domainMatches() does not match to sub-sub-domain
      • matchesCookiePath

        static boolean matchesCookiePath​(java.lang.String path,
                                         java.lang.String cookiePath)
        The utility method to check whether a path is matching a cookie path domain or not. The rules are defined by RFC 6265, section 5.1.4: A request-path path-matches a given cookie-path if at least one of the following conditions holds:
        • The cookie-path and the request-path are identical.
        • The cookie-path is a prefix of the request-path, and the last character of the cookie-path is %x2F ("/").
        • The cookie-path is a prefix of the request-path, and the first character of the request-path that is not included in the cookie- path is a %x2F ("/") character.
        Parameters:
        path - the path to check
        cookiePath - the cookie's path
        Returns:
        true if they path-match; false if not
      • isSmartHttp

        private boolean isSmartHttp​(HttpConnection c,
                                    java.lang.String service)
      • readSmartHeaders

        private void readSmartHeaders​(java.io.InputStream in,
                                      java.lang.String service)
                               throws java.io.IOException
        Throws:
        java.io.IOException