public class TransportHttp extends HttpTransport implements WalkTransport, PackTransport
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.
WalkFetchConnection| Modifier and Type | Class and Description |
|---|---|
static class |
TransportHttp.AcceptEncoding
Accept-Encoding header in the HTTP request
(https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html).
|
Transport.OperationconnectionFactoryDEFAULT_FETCH_THIN, DEFAULT_PUSH_THIN, local, REFSPEC_PUSH_ALL, REFSPEC_TAGS, uri| Modifier and Type | Method and Description |
|---|---|
void |
close() |
HttpConnectionFactory |
getHttpConnectionFactory()
Retrieves the
HttpConnectionFactory used by this
TransportHttp instance. |
protected HttpConnection |
httpOpen(String method,
URL u,
TransportHttp.AcceptEncoding acceptEncoding)
Open an HTTP connection.
|
FetchConnection |
openFetch()
Begins a new connection for fetching from the remote repository.
|
FetchConnection |
openFetch(Collection<RefSpec> refSpecs,
String... additionalPatterns)
Begins a new connection for fetching from the remote repository.
|
PushConnection |
openPush()
Begins a new connection for pushing into the remote repository.
|
void |
setAdditionalHeaders(Map<String,String> headers)
Set additional headers on the HTTP connection
|
void |
setHttpConnectionFactory(HttpConnectionFactory customFactory)
Sets the
HttpConnectionFactory to be used by this
TransportHttp instance. |
void |
setPreemptiveBasicAuthentication(String username,
String password)
Sets preemptive Basic HTTP authentication.
|
protected void |
setURI(URIish uri)
Set uri a
URIish object. |
void |
setUseSmartHttp(boolean on)
Toggle whether or not smart HTTP transport should be used.
|
getConnectionFactory, setConnectionFactoryapplyConfig, fetch, fetch, findRemoteRefUpdatesFor, findRemoteRefUpdatesFor, findRemoteRefUpdatesFor, findRemoteRefUpdatesFor, 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, unregisterprotected void setURI(URIish uri) throws NotSupportedException
URIish object.uri - a URIish object.NotSupportedExceptionpublic void setUseSmartHttp(boolean on)
This flag exists primarily to support backwards compatibility testing within a testing framework, there is no need to modify it in most applications.
on - if true (default), smart HTTP is enabled.public void setHttpConnectionFactory(@NonNull HttpConnectionFactory customFactory)
HttpConnectionFactory to be used by this
TransportHttp instance.
If no factory is set explicitly, the TransportHttp instance uses
the globally defined
factory.
customFactory - the HttpConnectionFactory to useIllegalStateException - if an HTTP/HTTPS connection has already been opened on this
TransportHttp instance@NonNull public HttpConnectionFactory getHttpConnectionFactory()
HttpConnectionFactory used by this
TransportHttp instance.HttpConnectionFactorypublic void setPreemptiveBasicAuthentication(String username, String password)
username
or password is empty or null, no preemptive
authentication will be done. If username and password 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.
username - to usepassword - to useIllegalStateException - if an HTTP/HTTPS connection has already been opened on this
TransportHttp instancepublic FetchConnection openFetch() throws TransportException, NotSupportedException
If the transport has no local repository, the fetch connection can only be used for reading remote refs.
openFetch in class TransportTransportException - the remote connection could not be established.NotSupportedException - the implementation does not support fetching.public FetchConnection openFetch(Collection<RefSpec> refSpecs, String... additionalPatterns) throws NotSupportedException, TransportException
TransportIf 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 RefSpecs 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().
openFetch in class TransportrefSpecs - that will be fetched via
FetchConnection.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 ignoredNotSupportedException - the implementation does not support fetching.TransportException - the remote connection could not be established.public PushConnection openPush() throws NotSupportedException, TransportException
openPush in class TransportNotSupportedException - the implementation does not support pushing.TransportException - the remote connection could not be establishedpublic 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.
close in interface AutoCloseableclose in class Transportpublic void setAdditionalHeaders(Map<String,String> headers)
headers - a map of name:values that are to be set as headers on the HTTP
connectionprotected HttpConnection httpOpen(String method, URL u, TransportHttp.AcceptEncoding acceptEncoding) throws IOException
method - HTTP request methodu - url of the HTTP connectionacceptEncoding - accept-encoding header optionIOExceptionCopyright © 2021 Eclipse JGit Project. All rights reserved.