Package org.eclipse.jgit.util
Class HttpSupport
- java.lang.Object
-
- org.eclipse.jgit.util.HttpSupport
-
public class HttpSupport extends java.lang.ObjectExtra utilities to support usage of HTTP.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Set<java.lang.String>configuredHttpsProtocolsstatic java.lang.StringENCODING_GZIPThegzipencoding value forHDR_ACCEPT_ENCODING.static java.lang.StringENCODING_X_GZIPThex-gzipencoding value forHDR_ACCEPT_ENCODING.static java.lang.StringHDR_ACCEPTTheAcceptheader.static java.lang.StringHDR_ACCEPT_ENCODINGTheAccept-Encodingheader.static java.lang.StringHDR_ACCEPT_RANGESTheAccept-Rangesheader.static java.lang.StringHDR_AUTHORIZATIONTheAuthorizationheader.static java.lang.StringHDR_CACHE_CONTROLTheCache-Controlheader.static java.lang.StringHDR_CONTENT_ENCODINGTheContent-Encodingheader.static java.lang.StringHDR_CONTENT_LENGTHTheContent-Lengthheader.static java.lang.StringHDR_CONTENT_RANGETheContent-Rangeheader.static java.lang.StringHDR_CONTENT_TYPETheContent-Typeheader.static java.lang.StringHDR_COOKIETheCookieheader.static java.lang.StringHDR_DATETheDateheader.static java.lang.StringHDR_ETAGTheETagheader.static java.lang.StringHDR_EXPIRESTheExpiresheader.static java.lang.StringHDR_IF_MODIFIED_SINCETheIf-Modified-Sinceheader.static java.lang.StringHDR_IF_NONE_MATCHTheIf-None-Matchheader.static java.lang.StringHDR_IF_RANGETheIf-Rangeheader.static java.lang.StringHDR_LAST_MODIFIEDTheLast-Modifiedheader.static java.lang.StringHDR_LOCATIONTheLocationheader.static java.lang.StringHDR_PRAGMAThePragmaheader.static java.lang.StringHDR_RANGETheRangeheader.static java.lang.StringHDR_SERVERTheServerheader.static java.lang.StringHDR_SET_COOKIETheSet-Cookieheader.static java.lang.StringHDR_SET_COOKIE2TheSet-Cookie2header.static java.lang.StringHDR_USER_AGENTTheUser-Agentheader.static java.lang.StringHDR_WWW_AUTHENTICATETheWWW-Authenticateheader.private static org.slf4j.LoggerLOGstatic java.lang.StringMETHOD_GETTheGETHTTP method.static java.lang.StringMETHOD_HEADTheHEADHTTP method.static java.lang.StringMETHOD_POSTThePOSTHTTP method.static java.lang.StringMETHOD_PUTThePOSTHTTP method.static java.lang.StringTEXT_PLAINThe standardtext/plainMIME type.
-
Constructor Summary
Constructors Modifier Constructor Description privateHttpSupport()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidconfigureTLS(javax.net.ssl.SSLSocket socket)Enables all supported TLS protocol versions on the socket given.static voiddisableSslVerify(HttpConnection conn)Disable SSL and hostname verification for given HTTP connectionstatic voidencode(java.lang.StringBuilder urlstr, java.lang.String key)URL encode a value string into an output buffer.private static java.util.Set<java.lang.String>getConfiguredProtocols()private static java.lang.StringgetProperty(java.lang.String property)static java.net.ProxyproxyFor(java.net.ProxySelector proxySelector, java.net.URL u)Determine the proxy server (if any) needed to obtain a URL.static intresponse(java.net.HttpURLConnection c)Get the HTTP response code from the request.static intresponse(HttpConnection c)Get the HTTP response code from the request.static java.lang.StringresponseHeader(HttpConnection c, java.lang.String headerName)Extract a HTTP header from the response.static intscanToken(java.lang.String header, int from)Scan a RFC 7230 token as it appears in HTTP headers.
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
METHOD_GET
public static final java.lang.String METHOD_GET
TheGETHTTP method.- See Also:
- Constant Field Values
-
METHOD_HEAD
public static final java.lang.String METHOD_HEAD
TheHEADHTTP method.- Since:
- 4.3
- See Also:
- Constant Field Values
-
METHOD_PUT
public static final java.lang.String METHOD_PUT
ThePOSTHTTP method.- Since:
- 4.3
- See Also:
- Constant Field Values
-
METHOD_POST
public static final java.lang.String METHOD_POST
ThePOSTHTTP method.- See Also:
- Constant Field Values
-
HDR_CACHE_CONTROL
public static final java.lang.String HDR_CACHE_CONTROL
TheCache-Controlheader.- See Also:
- Constant Field Values
-
HDR_PRAGMA
public static final java.lang.String HDR_PRAGMA
ThePragmaheader.- See Also:
- Constant Field Values
-
HDR_USER_AGENT
public static final java.lang.String HDR_USER_AGENT
TheUser-Agentheader.- See Also:
- Constant Field Values
-
HDR_SERVER
public static final java.lang.String HDR_SERVER
TheServerheader.- Since:
- 4.0
- See Also:
- Constant Field Values
-
HDR_DATE
public static final java.lang.String HDR_DATE
TheDateheader.- See Also:
- Constant Field Values
-
HDR_EXPIRES
public static final java.lang.String HDR_EXPIRES
TheExpiresheader.- See Also:
- Constant Field Values
-
HDR_ETAG
public static final java.lang.String HDR_ETAG
TheETagheader.- See Also:
- Constant Field Values
-
HDR_IF_NONE_MATCH
public static final java.lang.String HDR_IF_NONE_MATCH
TheIf-None-Matchheader.- See Also:
- Constant Field Values
-
HDR_LAST_MODIFIED
public static final java.lang.String HDR_LAST_MODIFIED
TheLast-Modifiedheader.- See Also:
- Constant Field Values
-
HDR_IF_MODIFIED_SINCE
public static final java.lang.String HDR_IF_MODIFIED_SINCE
TheIf-Modified-Sinceheader.- See Also:
- Constant Field Values
-
HDR_ACCEPT
public static final java.lang.String HDR_ACCEPT
TheAcceptheader.- See Also:
- Constant Field Values
-
HDR_CONTENT_TYPE
public static final java.lang.String HDR_CONTENT_TYPE
TheContent-Typeheader.- See Also:
- Constant Field Values
-
HDR_CONTENT_LENGTH
public static final java.lang.String HDR_CONTENT_LENGTH
TheContent-Lengthheader.- See Also:
- Constant Field Values
-
HDR_CONTENT_ENCODING
public static final java.lang.String HDR_CONTENT_ENCODING
TheContent-Encodingheader.- See Also:
- Constant Field Values
-
HDR_CONTENT_RANGE
public static final java.lang.String HDR_CONTENT_RANGE
TheContent-Rangeheader.- See Also:
- Constant Field Values
-
HDR_ACCEPT_RANGES
public static final java.lang.String HDR_ACCEPT_RANGES
TheAccept-Rangesheader.- See Also:
- Constant Field Values
-
HDR_IF_RANGE
public static final java.lang.String HDR_IF_RANGE
TheIf-Rangeheader.- See Also:
- Constant Field Values
-
HDR_RANGE
public static final java.lang.String HDR_RANGE
TheRangeheader.- See Also:
- Constant Field Values
-
HDR_ACCEPT_ENCODING
public static final java.lang.String HDR_ACCEPT_ENCODING
TheAccept-Encodingheader.- See Also:
- Constant Field Values
-
HDR_LOCATION
public static final java.lang.String HDR_LOCATION
TheLocationheader.- Since:
- 4.7
- See Also:
- Constant Field Values
-
ENCODING_GZIP
public static final java.lang.String ENCODING_GZIP
Thegzipencoding value forHDR_ACCEPT_ENCODING.- See Also:
- Constant Field Values
-
ENCODING_X_GZIP
public static final java.lang.String ENCODING_X_GZIP
Thex-gzipencoding value forHDR_ACCEPT_ENCODING.- Since:
- 4.6
- See Also:
- Constant Field Values
-
TEXT_PLAIN
public static final java.lang.String TEXT_PLAIN
The standardtext/plainMIME type.- See Also:
- Constant Field Values
-
HDR_AUTHORIZATION
public static final java.lang.String HDR_AUTHORIZATION
TheAuthorizationheader.- See Also:
- Constant Field Values
-
HDR_WWW_AUTHENTICATE
public static final java.lang.String HDR_WWW_AUTHENTICATE
TheWWW-Authenticateheader.- See Also:
- Constant Field Values
-
HDR_COOKIE
public static final java.lang.String HDR_COOKIE
TheCookieheader.- Since:
- 5.4
- See Also:
- Constant Field Values
-
HDR_SET_COOKIE
public static final java.lang.String HDR_SET_COOKIE
TheSet-Cookieheader.- Since:
- 5.4
- See Also:
- Constant Field Values
-
HDR_SET_COOKIE2
public static final java.lang.String HDR_SET_COOKIE2
TheSet-Cookie2header.- Since:
- 5.4
- See Also:
- Constant Field Values
-
configuredHttpsProtocols
private static java.util.Set<java.lang.String> configuredHttpsProtocols
-
-
Method Detail
-
encode
public static void encode(java.lang.StringBuilder urlstr, java.lang.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.
-
response
public static int response(HttpConnection c) throws java.io.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
HttpConnectionfor other defined constants. - Throws:
java.io.IOException- communications error prevented obtaining the response code.- Since:
- 3.3
-
response
public static int response(java.net.HttpURLConnection c) throws java.io.IOExceptionGet 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:
java.io.IOException- communications error prevented obtaining the response code.
-
responseHeader
public static java.lang.String responseHeader(HttpConnection c, java.lang.String headerName) throws java.io.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:
java.io.IOException- communications error prevented obtaining the header.- Since:
- 4.7
-
proxyFor
public static java.net.Proxy proxyFor(java.net.ProxySelector proxySelector, java.net.URL u) throws java.net.ConnectExceptionDetermine 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:
java.net.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 java.io.IOException
Disable SSL and hostname verification for given HTTP connection- Parameters:
conn- aHttpConnectionobject.- Throws:
java.io.IOException- Since:
- 4.3
-
configureTLS
public static void configureTLS(javax.net.ssl.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
-
getConfiguredProtocols
private static java.util.Set<java.lang.String> getConfiguredProtocols()
-
getProperty
private static java.lang.String getProperty(java.lang.String property)
-
scanToken
public static int scanToken(java.lang.String header, int from)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:
java.lang.IndexOutOfBoundsException- iffrom < 0orfrom > header.length()- Since:
- 5.10
- See Also:
- RFC 7230, Appendix B: Collected Grammar; "token" production
-
-