Class TransportHttp
- java.lang.Object
-
- org.eclipse.jgit.transport.Transport
-
- org.eclipse.jgit.transport.HttpTransport
-
- org.eclipse.jgit.transport.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TransportHttp.AcceptEncoding
Accept-Encoding header in the HTTP request (https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html).private static class
TransportHttp.CredentialItems
(package private) class
TransportHttp.HttpObjectDB
(package private) class
TransportHttp.LongPollService
Service for maintaining a single long-poll connection.(package private) class
TransportHttp.MultiRequestService
State required to speak multiple HTTP requests with the remote.(package private) class
TransportHttp.Service
Basic service for sending and receiving HTTP requests.(package private) class
TransportHttp.SmartHttpFetchConnection
(package private) class
TransportHttp.SmartHttpPushConnection
-
Nested classes/interfaces inherited from class org.eclipse.jgit.transport.Transport
Transport.Operation
-
-
Field Summary
Fields Modifier and Type Field Description private HttpAuthMethod
authMethod
private java.net.URL
baseUrl
private NetscapeCookieFile
cookieFile
All stored cookies bound to this repo (independent of the baseUrl)private URIish
currentUri
The current URI we're talking to.private HttpConnectionFactory
factory
private boolean
factoryUsed
private HttpConnectionFactory2.GitSession
gitSession
private java.util.Map<java.lang.String,java.lang.String>
headers
private HttpConfig
http
private static org.slf4j.Logger
LOG
private java.net.URL
objectsUrl
(package private) static TransportProtocol
PROTO_FTP
(package private) static TransportProtocol
PROTO_HTTP
private java.net.ProxySelector
proxySelector
private java.util.Set<java.net.HttpCookie>
relevantCookies
The cookies to be sent with each request to the givenbaseUrl
.private boolean
sslFailure
private boolean
sslVerify
private static java.lang.String
SVC_RECEIVE_PACK
private static java.lang.String
SVC_UPLOAD_PACK
private boolean
useSmartHttp
private static byte[]
VERSION
-
Fields inherited from class org.eclipse.jgit.transport.HttpTransport
connectionFactory
-
Fields inherited from class org.eclipse.jgit.transport.Transport
DEFAULT_FETCH_THIN, DEFAULT_PUSH_THIN, local, protocol, REFSPEC_PUSH_ALL, REFSPEC_TAGS, uri
-
-
Constructor Summary
Constructors Constructor Description TransportHttp(Repository local, URIish uri)
TransportHttp(URIish uri)
Create a minimal HTTP transport with default configuration values.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static void
addHeaders(HttpConnection conn, java.util.List<java.lang.String> headersToAdd)
Adds a list of header strings to the connection.private HttpAuthMethod
authFromUri(URIish u)
void
close()
private HttpConnection
connect(java.lang.String service)
private HttpConnection
connect(java.lang.String service, TransferConfig.ProtocolVersion protocolVersion)
private TransportHttp.CredentialItems
constructSslTrustItems(java.lang.Throwable cause)
private NoRemoteRepositoryException
createNotFoundException(URIish u, java.net.URL url, java.lang.String msg)
private java.util.List<java.net.HttpCookie>
extractCookies(java.lang.String headerKey, java.util.List<java.lang.String> headerValues)
private static java.util.Set<java.net.HttpCookie>
filterCookies(java.util.Set<java.net.HttpCookie> allCookies, java.net.URL url)
private static java.util.Set<java.net.HttpCookie>
filterCookies(NetscapeCookieFile cookieFile, java.net.URL url)
private FetchConnection
getConnection(HttpConnection c, java.io.InputStream in, java.lang.String service, java.util.Collection<RefSpec> refSpecs, java.lang.String... additionalPatterns)
private NetscapeCookieFile
getCookieFileFromConfig(HttpConfig config)
HttpConnectionFactory
getHttpConnectionFactory()
Retrieves theHttpConnectionFactory
used by thisTransportHttp
instance.private java.net.URL
getServiceURL(java.lang.String service)
private void
handleSslFailure(java.lang.Throwable e)
protected HttpConnection
httpOpen(java.lang.String method, java.net.URL u, TransportHttp.AcceptEncoding acceptEncoding)
Open an HTTP connection.private boolean
isGzipContent(HttpConnection c)
private boolean
isSmartHttp(HttpConnection c, java.lang.String service)
private boolean
isValidRedirect(java.net.URL current, java.lang.String next, java.lang.String checkFor)
(package private) 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.(package private) 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.private WalkFetchConnection
newDumbConnection(java.io.InputStream in)
FetchConnection
openFetch()
Begins a new connection for fetching from the remote repository.FetchConnection
openFetch(java.util.Collection<RefSpec> refSpecs, java.lang.String... additionalPatterns)
Begins a new connection for fetching from the remote repository.(package private) java.io.InputStream
openInputStream(HttpConnection conn)
PushConnection
openPush()
Begins a new connection for pushing into the remote repository.(package private) void
processResponseCookies(HttpConnection conn)
private void
readSmartHeaders(java.io.InputStream in, java.lang.String service)
private URIish
redirect(java.net.URL currentUrl, java.lang.String location, java.lang.String checkFor, int redirects)
void
setAdditionalHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
Set additional headers on the HTTP connectionprivate void
setCookieHeader(HttpConnection conn)
void
setHttpConnectionFactory(HttpConnectionFactory customFactory)
Sets theHttpConnectionFactory
to be used by thisTransportHttp
instance.void
setPreemptiveBasicAuthentication(java.lang.String username, java.lang.String password)
Sets preemptive Basic HTTP authentication.protected void
setURI(URIish uri)
Set uri aURIish
object.void
setUseSmartHttp(boolean on)
Toggle whether or not smart HTTP transport should be used.private PushConnection
smartPush(java.lang.String service, HttpConnection c, java.io.InputStream in)
private java.io.BufferedReader
toBufferedReader(java.io.InputStream in)
private java.net.URL
toURL(URIish urish)
private boolean
trustInsecureSslConnection(java.lang.Throwable cause)
private void
updateSslVerify(StoredConfig config, boolean value)
private void
updateSslVerifyUser(boolean value)
(package private) java.io.IOException
wrongContentType(java.lang.String expType, java.lang.String actType)
-
Methods inherited from class org.eclipse.jgit.transport.HttpTransport
getConnectionFactory, setConnectionFactory
-
Methods inherited from class org.eclipse.jgit.transport.Transport
applyConfig, fetch, fetch, findRemoteRefUpdatesFor, findRemoteRefUpdatesFor, findRemoteRefUpdatesFor, findRemoteRefUpdatesFor, findTrackingRefName, getCredentialsProvider, getFilterBlobLimit, getFilterSpec, getObjectChecker, getOptionReceivePack, getOptionUploadPack, getPackConfig, getPushOptions, getTagOpt, getTimeout, getTransportProtocols, getURI, isCheckFetchedObjects, isDryRun, isFetchThin, isPushAtomic, isPushThin, isRemoveDeletedRefs, open, open, open, open, open, open, open, openAll, openAll, openAll, openAll, push, push, register, setCheckFetchedObjects, setCredentialsProvider, setDryRun, setFetchThin, setFilterBlobLimit, setFilterSpec, setObjectChecker, setOptionReceivePack, setOptionUploadPack, setPackConfig, setPushAtomic, setPushOptions, setPushThin, setRemoveDeletedRefs, setTagOpt, setTimeout, unregister
-
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
SVC_UPLOAD_PACK
private static final java.lang.String SVC_UPLOAD_PACK
- See Also:
- Constant Field Values
-
SVC_RECEIVE_PACK
private static final java.lang.String SVC_RECEIVE_PACK
- See Also:
- Constant Field Values
-
VERSION
private static final byte[] VERSION
-
PROTO_HTTP
static final TransportProtocol PROTO_HTTP
-
PROTO_FTP
static final TransportProtocol PROTO_FTP
-
currentUri
private URIish currentUri
The current URI we're talking to. The inherited (final) fieldTransport.uri
stores the original URI;currentUri
may be different after redirects.
-
baseUrl
private java.net.URL baseUrl
-
objectsUrl
private java.net.URL objectsUrl
-
http
private final HttpConfig http
-
proxySelector
private final java.net.ProxySelector proxySelector
-
useSmartHttp
private boolean useSmartHttp
-
authMethod
private HttpAuthMethod authMethod
-
headers
private java.util.Map<java.lang.String,java.lang.String> headers
-
sslVerify
private boolean sslVerify
-
sslFailure
private boolean sslFailure
-
factory
private HttpConnectionFactory factory
-
gitSession
private HttpConnectionFactory2.GitSession gitSession
-
factoryUsed
private boolean factoryUsed
-
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 givenbaseUrl
. Filtered view on top ofcookieFile
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.
-
-
Constructor Detail
-
TransportHttp
TransportHttp(Repository local, URIish uri) throws NotSupportedException
- Throws:
NotSupportedException
-
TransportHttp
TransportHttp(URIish uri) throws NotSupportedException
Create a minimal HTTP transport with default configuration values.- Parameters:
uri
-- Throws:
NotSupportedException
-
-
Method Detail
-
toURL
private java.net.URL toURL(URIish urish) throws java.net.MalformedURLException
- Throws:
java.net.MalformedURLException
-
setURI
protected void setURI(URIish uri) throws NotSupportedException
Set uri aURIish
object.- Parameters:
uri
- aURIish
object.- Throws:
NotSupportedException
- Since:
- 4.9
-
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
- iftrue
(default), smart HTTP is enabled.
-
getConnection
private FetchConnection getConnection(HttpConnection c, java.io.InputStream in, java.lang.String service, java.util.Collection<RefSpec> refSpecs, java.lang.String... additionalPatterns) throws java.io.IOException
- Throws:
java.io.IOException
-
setHttpConnectionFactory
public void setHttpConnectionFactory(@NonNull HttpConnectionFactory customFactory)
Sets theHttpConnectionFactory
to be used by thisTransportHttp
instance.If no factory is set explicitly, the
TransportHttp
instance uses theglobally defined factory
.- Parameters:
customFactory
- theHttpConnectionFactory
to use- Throws:
java.lang.IllegalStateException
- if an HTTP/HTTPS connection has already been opened on thisTransportHttp
instance- Since:
- 5.11
-
getHttpConnectionFactory
@NonNull public HttpConnectionFactory getHttpConnectionFactory()
Retrieves theHttpConnectionFactory
used by thisTransportHttp
instance.- Returns:
- the
HttpConnectionFactory
- Since:
- 5.11
-
setPreemptiveBasicAuthentication
public void setPreemptiveBasicAuthentication(java.lang.String username, java.lang.String password)
Sets preemptive Basic HTTP authentication. If the givenusername
orpassword
is empty ornull
, no preemptive authentication will be done. Ifusername
andpassword
are set, they will override authority information from the URI ("user:password@").If the connection encounters redirects, the pre-authentication will be cleared if the redirect goes to a different host.
- Parameters:
username
- to usepassword
- to use- Throws:
java.lang.IllegalStateException
- if an HTTP/HTTPS connection has already been opened on thisTransportHttp
instance- Since:
- 5.11
-
openFetch
public FetchConnection openFetch() throws TransportException, NotSupportedException
Begins a new connection for fetching from the remote repository.If the transport has no local repository, the fetch connection can only be used for reading remote refs.
- Specified by:
openFetch
in classTransport
- Returns:
- a fresh connection to fetch from the remote repository.
- Throws:
TransportException
- the remote connection could not be established.NotSupportedException
- the implementation does not support fetching.
-
openFetch
public FetchConnection openFetch(java.util.Collection<RefSpec> refSpecs, java.lang.String... additionalPatterns) throws NotSupportedException, TransportException
Description copied from class:Transport
Begins a new connection for fetching from the remote repository.If the transport has no local repository, the fetch connection can only be used for reading remote refs.
If the server supports git protocol V2, the
RefSpec
s and the additional patterns, if any, are used to restrict the server's ref advertisement to matching refs only.Transports that want to support git protocol V2 must override this; the default implementation ignores its arguments and calls
Transport.openFetch()
.- Overrides:
openFetch
in classTransport
- Parameters:
refSpecs
- that will be fetched viaFetchConnection.fetch(ProgressMonitor, Collection, java.util.Set, OutputStream)
lateradditionalPatterns
- that will be set as ref prefixes if the server supports git protocol V2;null
values are ignored- Returns:
- a fresh connection to fetch from the remote repository.
- Throws:
NotSupportedException
- the implementation does not support fetching.TransportException
- the remote connection could not be established.
-
newDumbConnection
private WalkFetchConnection newDumbConnection(java.io.InputStream in) throws java.io.IOException, PackProtocolException
- Throws:
java.io.IOException
PackProtocolException
-
toBufferedReader
private java.io.BufferedReader toBufferedReader(java.io.InputStream in)
-
openPush
public PushConnection openPush() throws NotSupportedException, TransportException
Begins a new connection for pushing into the remote repository.- Specified by:
openPush
in classTransport
- Returns:
- a fresh connection to push into the remote repository.
- Throws:
NotSupportedException
- the implementation does not support pushing.TransportException
- the remote connection could not be established
-
smartPush
private PushConnection smartPush(java.lang.String service, HttpConnection c, java.io.InputStream in) throws java.io.IOException, TransportException
- Throws:
java.io.IOException
TransportException
-
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 throwsException
. Implementers shouldn't throw checked exceptions. This override narrows the signature to prevent them from doing so.
-
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
-
createNotFoundException
private NoRemoteRepositoryException createNotFoundException(URIish u, java.net.URL url, java.lang.String msg)
-
authFromUri
private HttpAuthMethod authFromUri(URIish u)
-
connect
private HttpConnection connect(java.lang.String service) throws TransportException, NotSupportedException
-
connect
private HttpConnection connect(java.lang.String service, TransferConfig.ProtocolVersion protocolVersion) throws TransportException, NotSupportedException
-
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)
-
handleSslFailure
private void handleSslFailure(java.lang.Throwable e) throws TransportException
- Throws:
TransportException
-
trustInsecureSslConnection
private boolean trustInsecureSslConnection(java.lang.Throwable cause)
-
constructSslTrustItems
private TransportHttp.CredentialItems constructSslTrustItems(java.lang.Throwable cause)
-
updateSslVerify
private void updateSslVerify(StoredConfig config, boolean value)
-
updateSslVerifyUser
private void updateSslVerifyUser(boolean value)
-
redirect
private URIish redirect(java.net.URL currentUrl, java.lang.String location, java.lang.String checkFor, int redirects) throws TransportException
- Throws:
TransportException
-
isValidRedirect
private boolean isValidRedirect(java.net.URL current, java.lang.String next, java.lang.String checkFor)
-
getServiceURL
private java.net.URL getServiceURL(java.lang.String service) throws NotSupportedException
- Throws:
NotSupportedException
-
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 methodu
- url of the HTTP connectionacceptEncoding
- 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 HttpConnectionheadersToAdd
- 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)
-
getCookieFileFromConfig
private NetscapeCookieFile getCookieFileFromConfig(HttpConfig config)
-
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 toHttpCookie.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 cookieDomaincookieDomain
- 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 checkcookiePath
- the cookie's path- Returns:
true
if they path-match;false
if not
-
isSmartHttp
private boolean isSmartHttp(HttpConnection c, java.lang.String service)
-
isGzipContent
private boolean isGzipContent(HttpConnection c)
-
readSmartHeaders
private void readSmartHeaders(java.io.InputStream in, java.lang.String service) throws java.io.IOException
- Throws:
java.io.IOException
-
-