Class HttpSupport
java.lang.Object
org.eclipse.jgit.util.HttpSupport
Extra utilities to support usage of HTTP.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThegzipencoding value forHDR_ACCEPT_ENCODING.static final StringThex-gzipencoding value forHDR_ACCEPT_ENCODING.static final StringTheAcceptheader.static final StringTheAccept-Encodingheader.static final StringTheAccept-Rangesheader.static final StringTheAuthorizationheader.static final StringTheCache-Controlheader.static final StringTheContent-Encodingheader.static final StringTheContent-Lengthheader.static final StringTheContent-Rangeheader.static final StringTheContent-Typeheader.static final StringTheCookieheader.static final StringTheDateheader.static final StringTheETagheader.static final StringTheExpiresheader.static final StringTheIf-Modified-Sinceheader.static final StringTheIf-None-Matchheader.static final StringTheIf-Rangeheader.static final StringTheLast-Modifiedheader.static final StringTheLocationheader.static final StringThePragmaheader.static final StringTheRangeheader.static final StringTheServerheader.static final StringTheSet-Cookieheader.static final StringTheSet-Cookie2header.static final StringTheUser-Agentheader.static final StringTheWWW-Authenticateheader.private static final org.slf4j.Loggerstatic final StringTheGETHTTP method.static final StringTheHEADHTTP method.static final StringThePOSTHTTP method.static final StringThePOSTHTTP method.static final StringThe standardtext/plainMIME type. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidconfigureTLS(SSLSocket socket) Enables all supported TLS protocol versions on the socket given.static voidDisable SSL and hostname verification for given HTTP connectionstatic voidencode(StringBuilder urlstr, String key) URL encode a value string into an output buffer.private static StringgetProperty(String property) static ProxyproxyFor(ProxySelector proxySelector, URL u) Determine the proxy server (if any) needed to obtain a URL.static intGet the HTTP response code from the request.static intGet the HTTP response code from the request.static StringresponseHeader(HttpConnection c, String headerName) Extract a HTTP header from the response.static intScan a RFC 7230 token as it appears in HTTP headers.
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
METHOD_GET
-
METHOD_HEAD
-
METHOD_PUT
-
METHOD_POST
-
HDR_CACHE_CONTROL
-
HDR_PRAGMA
-
HDR_USER_AGENT
-
HDR_SERVER
-
HDR_DATE
-
HDR_EXPIRES
-
HDR_ETAG
-
HDR_IF_NONE_MATCH
-
HDR_LAST_MODIFIED
-
HDR_IF_MODIFIED_SINCE
-
HDR_ACCEPT
-
HDR_CONTENT_TYPE
-
HDR_CONTENT_LENGTH
-
HDR_CONTENT_ENCODING
-
HDR_CONTENT_RANGE
-
HDR_ACCEPT_RANGES
-
HDR_IF_RANGE
-
HDR_RANGE
-
HDR_ACCEPT_ENCODING
-
HDR_LOCATION
-
ENCODING_GZIP
-
ENCODING_X_GZIP
Thex-gzipencoding value forHDR_ACCEPT_ENCODING.- Since:
- 4.6
- See Also:
-
TEXT_PLAIN
-
HDR_AUTHORIZATION
-
HDR_WWW_AUTHENTICATE
-
HDR_COOKIE
-
HDR_SET_COOKIE
-
HDR_SET_COOKIE2
-
configuredHttpsProtocols
-
-
Constructor Details
-
HttpSupport
private HttpSupport()
-
-
Method Details
-
encode
URL encode a value string into an output buffer.- Parameters:
urlstr- the output buffer.key- value which must be encoded to protected special characters.
-
response
Get the HTTP response code from the request.Roughly the same as
c.getResponseCode()but the ConnectException is translated to be more understandable.- Parameters:
c- connection the code should be obtained from.- Returns:
- r HTTP status code, usually 200 to indicate success. See
HttpConnectionfor other defined constants. - Throws:
IOException- communications error prevented obtaining the response code.- Since:
- 3.3
-
response
Get the HTTP response code from the request.Roughly the same as
c.getResponseCode()but the ConnectException is translated to be more understandable.- Parameters:
c- connection the code should be obtained from.- Returns:
- r HTTP status code, usually 200 to indicate success. See
HttpConnectionfor other defined constants. - Throws:
IOException- communications error prevented obtaining the response code.
-
responseHeader
Extract a HTTP header from the response.- Parameters:
c- connection the header should be obtained from.headerName- the header name- Returns:
- the header value
- Throws:
IOException- communications error prevented obtaining the header.- Since:
- 4.7
-
proxyFor
Determine the proxy server (if any) needed to obtain a URL.- Parameters:
proxySelector- proxy support for the caller.u- location of the server caller wants to talk to.- Returns:
- proxy to communicate with the supplied URL.
- Throws:
ConnectException- the proxy could not be computed as the supplied URL could not be read. This failure should never occur.
-
disableSslVerify
Disable SSL and hostname verification for given HTTP connection- Parameters:
conn- aHttpConnectionobject.- Throws:
IOException- Since:
- 4.3
-
configureTLS
Enables all supported TLS protocol versions on the socket given. If system property "https.protocols" is set, only protocols specified there are enabled.This is primarily a mechanism to deal with using TLS on IBM JDK. IBM JDK returns sockets that support all TLS protocol versions but have only the one specified in the context enabled. Oracle or OpenJDK return sockets that have all available protocols enabled already, up to the one specified.
SSLContext.getInstance() OpenJDK IDM JDK "TLS" Supported: TLSv1, TLSV1.1, TLSv1.2 (+ TLSv1.3)
Enabled: TLSv1, TLSV1.1, TLSv1.2 (+ TLSv1.3)Supported: TLSv1, TLSV1.1, TLSv1.2
Enabled: TLSv1"TLSv1.2" Supported: TLSv1, TLSV1.1, TLSv1.2
Enabled: TLSv1, TLSV1.1, TLSv1.2Supported: TLSv1, TLSV1.1, TLSv1.2
Enabled: TLSv1.2- Parameters:
socket- to configure- Since:
- 5.7
- See Also:
-
getConfiguredProtocols
-
getProperty
-
scanToken
Scan a RFC 7230 token as it appears in HTTP headers.- Parameters:
header- to scan infrom- index inheaderto start scanning at- Returns:
- the index after the token, that is, on the first non-token
character or
header.length - Throws:
IndexOutOfBoundsException- iffrom < 0orfrom > header.length()- Since:
- 5.10
- See Also:
-