Top Description Fields Constructors Methods
org.eclipse.jgit.util

public Class HttpSupport

extends Object
Class Inheritance
Static Imports
java.nio.charset.StandardCharsets.UTF_8

Extra utilities to support usage of HTTP.

Field Summary

Modifier and TypeField and Description
private static Set<String>
public static final String
ENCODING_GZIP

The gzip encoding value for HDR_ACCEPT_ENCODING.

public static final String
ENCODING_X_GZIP

The x-gzip encoding value for HDR_ACCEPT_ENCODING.

public static final String
HDR_ACCEPT

The Accept header.

public static final String
HDR_ACCEPT_ENCODING

The Accept-Encoding header.

public static final String
HDR_ACCEPT_RANGES

The Accept-Ranges header.

public static final String
HDR_AUTHORIZATION

The Authorization header.

public static final String
HDR_CACHE_CONTROL

The Cache-Control header.

public static final String
HDR_CONTENT_ENCODING

The Content-Encoding header.

public static final String
HDR_CONTENT_LENGTH

The Content-Length header.

public static final String
HDR_CONTENT_RANGE

The Content-Range header.

public static final String
HDR_CONTENT_TYPE

The Content-Type header.

public static final String
HDR_COOKIE

The Cookie header.

public static final String
HDR_DATE

The Date header.

public static final String
HDR_ETAG

The ETag header.

public static final String
HDR_EXPIRES

The Expires header.

public static final String
HDR_IF_MODIFIED_SINCE

The If-Modified-Since header.

public static final String
HDR_IF_NONE_MATCH

The If-None-Match header.

public static final String
HDR_IF_RANGE

The If-Range header.

public static final String
HDR_LAST_MODIFIED

The Last-Modified header.

public static final String
HDR_LOCATION

The Location header.

public static final String
HDR_PRAGMA

The Pragma header.

public static final String
HDR_RANGE

The Range header.

public static final String
HDR_SERVER

The Server header.

public static final String
HDR_SET_COOKIE

The Set-Cookie header.

public static final String
HDR_SET_COOKIE2

The Set-Cookie2 header.

public static final String
HDR_USER_AGENT

The User-Agent header.

public static final String
HDR_WWW_AUTHENTICATE

The WWW-Authenticate header.

private static final Logger
public static final String
METHOD_GET

The GET HTTP method.

public static final String
METHOD_HEAD

The HEAD HTTP method.

public static final String
METHOD_POST

The POST HTTP method.

public static final String
METHOD_PUT

The POST HTTP method.

public static final String
TEXT_PLAIN

The standard text/plain MIME type.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
configureTLS(SSLSocket
to configure
socket
)

Enables all supported TLS protocol versions on the socket given.

public static void
disableSslVerify(HttpConnection conn)

Disable SSL and hostname verification for given HTTP connection

public static void
encode(StringBuilder
the output buffer.
urlstr
,
String
value which must be encoded to protected special characters.
key
)

URL encode a value string into an output buffer.

private static Set<String>
private static String
getProperty(String property)

public static Proxy

Returns:

proxy to communicate with the supplied URL.
proxyFor
(ProxySelector
proxy support for the caller.
proxySelector
,
URL
location of the server caller wants to talk to.
u
)

Determine the proxy server (if any) needed to obtain a URL.

public static int

Returns:

r HTTP status code, usually 200 to indicate success. See org.eclipse.jgit.transport.http.HttpConnection for other defined constants.
response
(HttpConnection
connection the code should be obtained from.
c
)

Get the HTTP response code from the request.

public static int

Returns:

r HTTP status code, usually 200 to indicate success. See org.eclipse.jgit.transport.http.HttpConnection for other defined constants.
response
(HttpURLConnection
connection the code should be obtained from.
c
)

Get the HTTP response code from the request.

public static String

Returns:

the header value
responseHeader
(final HttpConnection
connection the header should be obtained from.
c
,
final String
the header name
headerName
)

Extract a HTTP header from the response.

public static int

Returns:

the index after the token, that is, on the first non-token character or header.length
scanToken
(String
to scan in
header
,
int
index in header to start scanning at
from
)

Scan a RFC 7230 token as it appears in HTTP headers.

public static String

Returns:

The translated URL.
urlEncode
(String
The URL to translate.
url
,
boolean
Whether or not to keep "/" in the URL (i.e. don't translate them to "%2F").
keepPathSlash
)

Translates the provided URL into application/x-www-form-urlencoded format.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

configuredHttpsProtocolsback to summary
private static Set<String> configuredHttpsProtocols
ENCODING_GZIPback to summary
public static final String ENCODING_GZIP

The gzip encoding value for HDR_ACCEPT_ENCODING.

ENCODING_X_GZIPback to summary
public static final String ENCODING_X_GZIP

The x-gzip encoding value for HDR_ACCEPT_ENCODING.

Since
4.6
HDR_ACCEPTback to summary
public static final String HDR_ACCEPT

The Accept header.

HDR_ACCEPT_ENCODINGback to summary
public static final String HDR_ACCEPT_ENCODING

The Accept-Encoding header.

HDR_ACCEPT_RANGESback to summary
public static final String HDR_ACCEPT_RANGES

The Accept-Ranges header.

HDR_AUTHORIZATIONback to summary
public static final String HDR_AUTHORIZATION

The Authorization header.

HDR_CACHE_CONTROLback to summary
public static final String HDR_CACHE_CONTROL

The Cache-Control header.

HDR_CONTENT_ENCODINGback to summary
public static final String HDR_CONTENT_ENCODING

The Content-Encoding header.

HDR_CONTENT_LENGTHback to summary
public static final String HDR_CONTENT_LENGTH

The Content-Length header.

HDR_CONTENT_RANGEback to summary
public static final String HDR_CONTENT_RANGE

The Content-Range header.

HDR_CONTENT_TYPEback to summary
public static final String HDR_CONTENT_TYPE

The Content-Type header.

HDR_DATEback to summary
public static final String HDR_DATE

The Date header.

HDR_ETAGback to summary
public static final String HDR_ETAG

The ETag header.

HDR_EXPIRESback to summary
public static final String HDR_EXPIRES

The Expires header.

HDR_IF_MODIFIED_SINCEback to summary
public static final String HDR_IF_MODIFIED_SINCE

The If-Modified-Since header.

HDR_IF_NONE_MATCHback to summary
public static final String HDR_IF_NONE_MATCH

The If-None-Match header.

HDR_IF_RANGEback to summary
public static final String HDR_IF_RANGE

The If-Range header.

HDR_LAST_MODIFIEDback to summary
public static final String HDR_LAST_MODIFIED

The Last-Modified header.

HDR_LOCATIONback to summary
public static final String HDR_LOCATION

The Location header.

Since
4.7
HDR_PRAGMAback to summary
public static final String HDR_PRAGMA

The Pragma header.

HDR_RANGEback to summary
public static final String HDR_RANGE

The Range header.

HDR_SERVERback to summary
public static final String HDR_SERVER

The Server header.

Since
4.0
HDR_SET_COOKIE2back to summary
public static final String HDR_SET_COOKIE2

The Set-Cookie2 header.

Since
5.4
HDR_USER_AGENTback to summary
public static final String HDR_USER_AGENT

The User-Agent header.

HDR_WWW_AUTHENTICATEback to summary
public static final String HDR_WWW_AUTHENTICATE

The WWW-Authenticate header.

LOGback to summary
private static final Logger LOG
METHOD_GETback to summary
public static final String METHOD_GET

The GET HTTP method.

METHOD_HEADback to summary
public static final String METHOD_HEAD

The HEAD HTTP method.

Since
4.3
METHOD_POSTback to summary
public static final String METHOD_POST

The POST HTTP method.

METHOD_PUTback to summary
public static final String METHOD_PUT

The POST HTTP method.

Since
4.3
TEXT_PLAINback to summary
public static final String TEXT_PLAIN

The standard text/plain MIME type.

Constructor Detail

HttpSupportback to summary
private HttpSupport()

Method Detail

configureTLSback to summary
public static void configureTLS(SSLSocket socket)

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.


TLS versions
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.2
Supported: TLSv1, TLSV1.1, TLSv1.2
Enabled: TLSv1.2
Parameters
socket:SSLSocket

to configure

Since
5.7
See Also
Behavior of SSLContext.getInstance("TLS") on IBM JDK, Customizing JSSE about https.protocols
disableSslVerifyback to summary
public static void disableSslVerify(HttpConnection conn) throws IOException

Disable SSL and hostname verification for given HTTP connection

Parameters
conn:HttpConnection

a org.eclipse.jgit.transport.http.HttpConnection object.

Exceptions
IOException:
if an IO error occurred
Since
4.3
encodeback to summary
public static void encode(StringBuilder urlstr, String key)

URL encode a value string into an output buffer.

Parameters
urlstr:StringBuilder

the output buffer.

key:String

value which must be encoded to protected special characters.

getConfiguredProtocolsback to summary
private static Set<String> getConfiguredProtocols()
getPropertyback to summary
private static String getProperty(String property)
proxyForback to summary
public static Proxy proxyFor(ProxySelector proxySelector, URL u) throws ConnectException

Determine the proxy server (if any) needed to obtain a URL.

Parameters
proxySelector:ProxySelector

proxy support for the caller.

u:URL

location of the server caller wants to talk to.

Returns:Proxy

proxy to communicate with the supplied URL.

Exceptions
ConnectException:
the proxy could not be computed as the supplied URL could not be read. This failure should never occur.
responseback to summary
public static int response(HttpConnection c) throws IOException

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:HttpConnection

connection the code should be obtained from.

Returns:int

r HTTP status code, usually 200 to indicate success. See org.eclipse.jgit.transport.http.HttpConnection for other defined constants.

Exceptions
IOException:
communications error prevented obtaining the response code.
Since
3.3
responseback to summary
public static int response(HttpURLConnection c) throws IOException

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:HttpURLConnection

connection the code should be obtained from.

Returns:int

r HTTP status code, usually 200 to indicate success. See org.eclipse.jgit.transport.http.HttpConnection for other defined constants.

Exceptions
IOException:
communications error prevented obtaining the response code.
responseHeaderback to summary
public static String responseHeader(final HttpConnection c, final String headerName) throws IOException

Extract a HTTP header from the response.

Parameters
c:HttpConnection

connection the header should be obtained from.

headerName:String

the header name

Returns:String

the header value

Exceptions
IOException:
communications error prevented obtaining the header.
Since
4.7
scanTokenback to summary
public static int scanToken(String header, int from)

Scan a RFC 7230 token as it appears in HTTP headers.

Parameters
header:String

to scan in

from:int

index in header to start scanning at

Returns:int

the index after the token, that is, on the first non-token character or header.length

Exceptions
IndexOutOfBoundsException:
if from < 0 or from > header.length()
Since
5.10
See Also
RFC 7230, Appendix B: Collected Grammar; "token" production
urlEncodeback to summary
public static String urlEncode(String url, boolean keepPathSlash)

Translates the provided URL into application/x-www-form-urlencoded format.

Parameters
url:String

The URL to translate.

keepPathSlash:boolean

Whether or not to keep "/" in the URL (i.e. don't translate them to "%2F").

Returns:String

The translated URL.

Since
5.13.1