Package org.eclipse.jgit.util
Class HttpSupport
- java.lang.Object
-
- org.eclipse.jgit.util.HttpSupport
-
public class HttpSupport extends Object
Extra utilities to support usage of HTTP.
-
-
Field Summary
Fields Modifier and Type Field Description static String
ENCODING_GZIP
Thegzip
encoding value forHDR_ACCEPT_ENCODING
.static String
ENCODING_X_GZIP
Thex-gzip
encoding value forHDR_ACCEPT_ENCODING
.static String
HDR_ACCEPT
TheAccept
header.static String
HDR_ACCEPT_ENCODING
TheAccept-Encoding
header.static String
HDR_ACCEPT_RANGES
TheAccept-Ranges
header.static String
HDR_AUTHORIZATION
TheAuthorization
header.static String
HDR_CACHE_CONTROL
TheCache-Control
header.static String
HDR_CONTENT_ENCODING
TheContent-Encoding
header.static String
HDR_CONTENT_LENGTH
TheContent-Length
header.static String
HDR_CONTENT_RANGE
TheContent-Range
header.static String
HDR_CONTENT_TYPE
TheContent-Type
header.static String
HDR_COOKIE
TheCookie
header.static String
HDR_DATE
TheDate
header.static String
HDR_ETAG
TheETag
header.static String
HDR_EXPIRES
TheExpires
header.static String
HDR_IF_MODIFIED_SINCE
TheIf-Modified-Since
header.static String
HDR_IF_NONE_MATCH
TheIf-None-Match
header.static String
HDR_IF_RANGE
TheIf-Range
header.static String
HDR_LAST_MODIFIED
TheLast-Modified
header.static String
HDR_LOCATION
TheLocation
header.static String
HDR_PRAGMA
ThePragma
header.static String
HDR_RANGE
TheRange
header.static String
HDR_SERVER
TheServer
header.static String
HDR_SET_COOKIE
TheSet-Cookie
header.static String
HDR_SET_COOKIE2
TheSet-Cookie2
header.static String
HDR_USER_AGENT
TheUser-Agent
header.static String
HDR_WWW_AUTHENTICATE
TheWWW-Authenticate
header.static String
METHOD_GET
TheGET
HTTP method.static String
METHOD_HEAD
TheHEAD
HTTP method.static String
METHOD_POST
ThePOST
HTTP method.static String
METHOD_PUT
ThePOST
HTTP method.static String
TEXT_PLAIN
The standardtext/plain
MIME type.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
configureTLS(SSLSocket socket)
Enables all supported TLS protocol versions on the socket given.static void
disableSslVerify(HttpConnection conn)
Disable SSL and hostname verification for given HTTP connectionstatic void
encode(StringBuilder urlstr, String key)
URL encode a value string into an output buffer.static Proxy
proxyFor(ProxySelector proxySelector, URL u)
Determine the proxy server (if any) needed to obtain a URL.static int
response(HttpURLConnection c)
Get the HTTP response code from the request.static int
response(HttpConnection c)
Get the HTTP response code from the request.static String
responseHeader(HttpConnection c, String headerName)
Extract a HTTP header from the response.static int
scanToken(String header, int from)
Scan a RFC 7230 token as it appears in HTTP headers.static String
urlEncode(String url, boolean keepPathSlash)
Translates the provided URL into application/x-www-form-urlencoded format.
-
-
-
Field Detail
-
METHOD_GET
public static final String METHOD_GET
TheGET
HTTP method.- See Also:
- Constant Field Values
-
METHOD_HEAD
public static final String METHOD_HEAD
TheHEAD
HTTP method.- Since:
- 4.3
- See Also:
- Constant Field Values
-
METHOD_PUT
public static final String METHOD_PUT
ThePOST
HTTP method.- Since:
- 4.3
- See Also:
- Constant Field Values
-
METHOD_POST
public static final String METHOD_POST
ThePOST
HTTP method.- See Also:
- Constant Field Values
-
HDR_CACHE_CONTROL
public static final String HDR_CACHE_CONTROL
TheCache-Control
header.- See Also:
- Constant Field Values
-
HDR_PRAGMA
public static final String HDR_PRAGMA
ThePragma
header.- See Also:
- Constant Field Values
-
HDR_USER_AGENT
public static final String HDR_USER_AGENT
TheUser-Agent
header.- See Also:
- Constant Field Values
-
HDR_SERVER
public static final String HDR_SERVER
TheServer
header.- Since:
- 4.0
- See Also:
- Constant Field Values
-
HDR_DATE
public static final String HDR_DATE
TheDate
header.- See Also:
- Constant Field Values
-
HDR_EXPIRES
public static final String HDR_EXPIRES
TheExpires
header.- See Also:
- Constant Field Values
-
HDR_ETAG
public static final String HDR_ETAG
TheETag
header.- See Also:
- Constant Field Values
-
HDR_IF_NONE_MATCH
public static final String HDR_IF_NONE_MATCH
TheIf-None-Match
header.- See Also:
- Constant Field Values
-
HDR_LAST_MODIFIED
public static final String HDR_LAST_MODIFIED
TheLast-Modified
header.- See Also:
- Constant Field Values
-
HDR_IF_MODIFIED_SINCE
public static final String HDR_IF_MODIFIED_SINCE
TheIf-Modified-Since
header.- See Also:
- Constant Field Values
-
HDR_ACCEPT
public static final String HDR_ACCEPT
TheAccept
header.- See Also:
- Constant Field Values
-
HDR_CONTENT_TYPE
public static final String HDR_CONTENT_TYPE
TheContent-Type
header.- See Also:
- Constant Field Values
-
HDR_CONTENT_LENGTH
public static final String HDR_CONTENT_LENGTH
TheContent-Length
header.- See Also:
- Constant Field Values
-
HDR_CONTENT_ENCODING
public static final String HDR_CONTENT_ENCODING
TheContent-Encoding
header.- See Also:
- Constant Field Values
-
HDR_CONTENT_RANGE
public static final String HDR_CONTENT_RANGE
TheContent-Range
header.- See Also:
- Constant Field Values
-
HDR_ACCEPT_RANGES
public static final String HDR_ACCEPT_RANGES
TheAccept-Ranges
header.- See Also:
- Constant Field Values
-
HDR_IF_RANGE
public static final String HDR_IF_RANGE
TheIf-Range
header.- See Also:
- Constant Field Values
-
HDR_RANGE
public static final String HDR_RANGE
TheRange
header.- See Also:
- Constant Field Values
-
HDR_ACCEPT_ENCODING
public static final String HDR_ACCEPT_ENCODING
TheAccept-Encoding
header.- See Also:
- Constant Field Values
-
HDR_LOCATION
public static final String HDR_LOCATION
TheLocation
header.- Since:
- 4.7
- See Also:
- Constant Field Values
-
ENCODING_GZIP
public static final String ENCODING_GZIP
Thegzip
encoding value forHDR_ACCEPT_ENCODING
.- See Also:
- Constant Field Values
-
ENCODING_X_GZIP
public static final String ENCODING_X_GZIP
Thex-gzip
encoding value forHDR_ACCEPT_ENCODING
.- Since:
- 4.6
- See Also:
- Constant Field Values
-
TEXT_PLAIN
public static final String TEXT_PLAIN
The standardtext/plain
MIME type.- See Also:
- Constant Field Values
-
HDR_AUTHORIZATION
public static final String HDR_AUTHORIZATION
TheAuthorization
header.- See Also:
- Constant Field Values
-
HDR_WWW_AUTHENTICATE
public static final String HDR_WWW_AUTHENTICATE
TheWWW-Authenticate
header.- See Also:
- Constant Field Values
-
HDR_COOKIE
public static final String HDR_COOKIE
TheCookie
header.- Since:
- 5.4
- See Also:
- Constant Field Values
-
HDR_SET_COOKIE
public static final String HDR_SET_COOKIE
TheSet-Cookie
header.- Since:
- 5.4
- See Also:
- Constant Field Values
-
HDR_SET_COOKIE2
public static final String HDR_SET_COOKIE2
TheSet-Cookie2
header.- Since:
- 5.4
- See Also:
- Constant Field Values
-
-
Method Detail
-
encode
public static void encode(StringBuilder urlstr, String key)
URL encode a value string into an output buffer.- Parameters:
urlstr
- the output buffer.key
- value which must be encoded to protected special characters.
-
urlEncode
public static String urlEncode(String url, boolean keepPathSlash)
Translates the provided URL into application/x-www-form-urlencoded format.- Parameters:
url
- The URL to translate.keepPathSlash
- Whether or not to keep "/" in the URL (i.e. don't translate them to "%2F").- Returns:
- The translated URL.
- Since:
- 5.13
-
response
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
- connection the code should be obtained from.- Returns:
- r HTTP status code, usually 200 to indicate success. See
HttpConnection
for other defined constants. - Throws:
IOException
- communications error prevented obtaining the response code.- Since:
- 3.3
-
response
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
- connection the code should be obtained from.- Returns:
- r HTTP status code, usually 200 to indicate success. See
HttpConnection
for other defined constants. - Throws:
IOException
- communications error prevented obtaining the response code.
-
responseHeader
public static String responseHeader(HttpConnection c, String headerName) throws IOException
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
public static Proxy proxyFor(ProxySelector proxySelector, URL u) throws ConnectException
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
public static void disableSslVerify(HttpConnection conn) throws IOException
Disable SSL and hostname verification for given HTTP connection- Parameters:
conn
- aHttpConnection
object.- Throws:
IOException
- Since:
- 4.3
-
configureTLS
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.
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:
- Behavior of SSLContext.getInstance("TLS") on IBM JDK, Customizing JSSE about https.protocols
-
scanToken
public static int scanToken(String header, int from)
Scan a RFC 7230 token as it appears in HTTP headers.- Parameters:
header
- to scan infrom
- index inheader
to start scanning at- Returns:
- the index after the token, that is, on the first non-token
character or
header.length
- Throws:
IndexOutOfBoundsException
- iffrom < 0
orfrom > header.length()
- Since:
- 5.10
- See Also:
- RFC 7230, Appendix B: Collected Grammar; "token" production
-
-