- All Implemented Interfaces:
AutoCloseable
,PackTransport
,WalkTransport
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 ClassesModifier and TypeClassDescriptionstatic enum
Accept-Encoding header in the HTTP request (https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html).Nested classes/interfaces inherited from class org.eclipse.jgit.transport.Transport
Transport.Operation
-
Field Summary
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, DEFAULT_PUSH_USE_BITMAPS, local, REFSPEC_PUSH_ALL, REFSPEC_TAGS, uri
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Get additional headers on the HTTP connectionRetrieves theHttpConnectionFactory
used by thisTransportHttp
instance.protected HttpConnection
httpOpen
(String method, URL u, TransportHttp.AcceptEncoding acceptEncoding) Open an HTTP connection.Begins a new connection for fetching from the remote repository.openFetch
(Collection<RefSpec> refSpecs, String... additionalPatterns) Begins a new connection for fetching from the remote repository.openPush()
Begins a new connection for pushing into the remote repository.void
setAdditionalHeaders
(Map<String, String> headers) Set additional headers on the HTTP connectionvoid
setHttpConnectionFactory
(HttpConnectionFactory customFactory) Sets theHttpConnectionFactory
to be used by thisTransportHttp
instance.void
setPreemptiveBasicAuthentication
(String username, String password) Sets preemptive Basic HTTP authentication.protected void
Set uri aURIish
object.void
setUseSmartHttp
(boolean on) Toggle whether or not smart HTTP transport should be used.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, getCredentialsProvider, getDeepenNots, getDeepenSince, getDepth, getFilterBlobLimit, getFilterSpec, getObjectChecker, getOptionReceivePack, getOptionUploadPack, getPackConfig, getPushOptions, getTagOpt, getTimeout, getTransportProtocols, getURI, isCheckFetchedObjects, isDryRun, isFetchThin, isPushAtomic, isPushThin, isPushUseBitmaps, isRemoveDeletedRefs, open, open, open, open, open, open, open, openAll, openAll, openAll, openAll, push, push, register, setCheckFetchedObjects, setCredentialsProvider, setDeepenNots, setDeepenSince, setDepth, setDepth, setDryRun, setFetchThin, setFilterBlobLimit, setFilterSpec, setHookErrorStream, setHookOutputStream, setObjectChecker, setOptionReceivePack, setOptionUploadPack, setPackConfig, setPushAtomic, setPushOptions, setPushThin, setPushUseBitmaps, setRemoveDeletedRefs, setTagOpt, setTimeout, unregister
-
Method Details
-
setURI
Set uri aURIish
object.- Parameters:
uri
- aURIish
object.- Throws:
NotSupportedException
- if URI is not supported by JGit- 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.
-
setHttpConnectionFactory
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:
IllegalStateException
- if an HTTP/HTTPS connection has already been opened on thisTransportHttp
instance- Since:
- 5.11
-
getHttpConnectionFactory
Retrieves theHttpConnectionFactory
used by thisTransportHttp
instance.- Returns:
- the
HttpConnectionFactory
- Since:
- 5.11
-
setPreemptiveBasicAuthentication
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:
IllegalStateException
- if an HTTP/HTTPS connection has already been opened on thisTransportHttp
instance- Since:
- 5.11
-
openFetch
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.
- 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(Collection<RefSpec> refSpecs, 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.
-
openPush
Description copied from class:Transport
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
-
close
public void close()Description copied from class:Transport
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.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in classTransport
-
setAdditionalHeaders
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
-
getAdditionalHeaders
Get additional headers on the HTTP connection- Returns:
- unmodifiable map of additional name:values that are set as headers on the HTTP connection
- Since:
- 6.6
-
httpOpen
protected HttpConnection httpOpen(String method, URL u, TransportHttp.AcceptEncoding acceptEncoding) throws IOException Open an HTTP connection.- Parameters:
method
- HTTP request methodu
- url of the HTTP connectionacceptEncoding
- accept-encoding header option- Returns:
- the HTTP connection
- Throws:
IOException
- if an IO error occurred- Since:
- 4.6
-