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).
|
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 |
Transport.Operation
Modifier and Type | Field and 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 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 given
baseUrl . |
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 |
connectionFactory
DEFAULT_FETCH_THIN, DEFAULT_PUSH_THIN, local, REFSPEC_PUSH_ALL, REFSPEC_TAGS, uri
Constructor and Description |
---|
TransportHttp(Repository local,
URIish uri) |
TransportHttp(URIish uri)
Create a minimal HTTP transport with default configuration values.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
private HttpConnection |
connect(java.lang.String service) |
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(NetscapeCookieFile cookieFile,
java.net.URL url) |
private static java.util.Set<java.net.HttpCookie> |
filterCookies(java.util.Set<java.net.HttpCookie> allCookies,
java.net.URL url) |
private FetchConnection |
getConnection(HttpConnection c,
java.io.InputStream in,
java.lang.String service) |
private static NetscapeCookieFile |
getCookieFileFromConfig(HttpConfig config) |
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.
|
(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.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 connection
|
private void |
setCookieHeader(HttpConnection conn) |
protected void |
setURI(URIish uri)
Set uri a
URIish 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) |
getConnectionFactory, setConnectionFactory
applyConfig, 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, unregister
private static final org.slf4j.Logger LOG
private static final java.lang.String SVC_UPLOAD_PACK
private static final java.lang.String SVC_RECEIVE_PACK
static final TransportProtocol PROTO_HTTP
static final TransportProtocol PROTO_FTP
private URIish currentUri
Transport.uri
stores the original URI; currentUri
may be different
after redirects.private java.net.URL baseUrl
private java.net.URL objectsUrl
private final HttpConfig http
private final java.net.ProxySelector proxySelector
private boolean useSmartHttp
private HttpAuthMethod authMethod
private java.util.Map<java.lang.String,java.lang.String> headers
private boolean sslVerify
private boolean sslFailure
private final NetscapeCookieFile cookieFile
private final java.util.Set<java.net.HttpCookie> relevantCookies
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.TransportHttp(Repository local, URIish uri) throws NotSupportedException
NotSupportedException
TransportHttp(URIish uri) throws NotSupportedException
uri
- NotSupportedException
private java.net.URL toURL(URIish urish) throws java.net.MalformedURLException
java.net.MalformedURLException
protected void setURI(URIish uri) throws NotSupportedException
URIish
object.uri
- a URIish
object.NotSupportedException
public 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.private FetchConnection getConnection(HttpConnection c, java.io.InputStream in, java.lang.String service) throws java.io.IOException
java.io.IOException
public 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 Transport
TransportException
- the remote connection could not be established.NotSupportedException
- the implementation does not support fetching.private WalkFetchConnection newDumbConnection(java.io.InputStream in) throws java.io.IOException, PackProtocolException
java.io.IOException
PackProtocolException
private java.io.BufferedReader toBufferedReader(java.io.InputStream in)
public PushConnection openPush() throws NotSupportedException, TransportException
openPush
in class Transport
NotSupportedException
- the implementation does not support pushing.TransportException
- the remote connection could not be establishedprivate PushConnection smartPush(java.lang.String service, HttpConnection c, java.io.InputStream in) throws java.io.IOException, TransportException
java.io.IOException
TransportException
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.
public void setAdditionalHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
headers
- a map of name:values that are to be set as headers on the HTTP
connectionprivate NoRemoteRepositoryException createNotFoundException(URIish u, java.net.URL url, java.lang.String msg)
private HttpConnection connect(java.lang.String service) throws TransportException, NotSupportedException
void processResponseCookies(HttpConnection conn)
private java.util.List<java.net.HttpCookie> extractCookies(java.lang.String headerKey, java.util.List<java.lang.String> headerValues)
private void handleSslFailure(java.lang.Throwable e) throws TransportException
TransportException
private boolean trustInsecureSslConnection(java.lang.Throwable cause)
private TransportHttp.CredentialItems constructSslTrustItems(java.lang.Throwable cause)
private void updateSslVerify(StoredConfig config, boolean value)
private void updateSslVerifyUser(boolean value)
private URIish redirect(java.lang.String location, java.lang.String checkFor, int redirects) throws TransportException
TransportException
private boolean isValidRedirect(java.net.URL current, java.lang.String next, java.lang.String checkFor)
private java.net.URL getServiceURL(java.lang.String service) throws NotSupportedException
NotSupportedException
protected HttpConnection httpOpen(java.lang.String method, java.net.URL u, TransportHttp.AcceptEncoding acceptEncoding) throws java.io.IOException
method
- HTTP request methodu
- url of the HTTP connectionacceptEncoding
- accept-encoding header optionjava.io.IOException
private void setCookieHeader(HttpConnection conn)
final java.io.InputStream openInputStream(HttpConnection conn) throws java.io.IOException
java.io.IOException
java.io.IOException wrongContentType(java.lang.String expType, java.lang.String actType)
private static NetscapeCookieFile getCookieFileFromConfig(HttpConfig config)
private static java.util.Set<java.net.HttpCookie> filterCookies(NetscapeCookieFile cookieFile, java.net.URL url)
private static java.util.Set<java.net.HttpCookie> filterCookies(java.util.Set<java.net.HttpCookie> allCookies, java.net.URL url)
allCookies
- a list of cookies.url
- the url for which to filter the list of cookies.allCookies
which are relevant (i.e.
are not expired, have a matching domain, have a matching path and
have a matching secure attribute)static boolean matchesCookieDomain(java.lang.String host, java.lang.String cookieDomain)
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:
host
- the host to compare against the cookieDomaincookieDomain
- the domain to compare againsttrue
if they domain-match; false
if notstatic boolean matchesCookiePath(java.lang.String path, java.lang.String cookiePath)
path
- the path to checkcookiePath
- the cookie's pathtrue
if they path-match; false
if notprivate boolean isSmartHttp(HttpConnection c, java.lang.String service)
private boolean isGzipContent(HttpConnection c)
private void readSmartHeaders(java.io.InputStream in, java.lang.String service) throws java.io.IOException
java.io.IOException