public class HttpSupport
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
HttpSupport.DummyHostnameVerifier |
private static class |
HttpSupport.DummyX509TrustManager |
Modifier and Type | Field and Description |
---|---|
private static java.util.Set<java.lang.String> |
configuredHttpsProtocols |
static java.lang.String |
ENCODING_GZIP
The
gzip encoding value for HDR_ACCEPT_ENCODING . |
static java.lang.String |
ENCODING_X_GZIP
The
x-gzip encoding value for HDR_ACCEPT_ENCODING . |
static java.lang.String |
HDR_ACCEPT
The
Accept header. |
static java.lang.String |
HDR_ACCEPT_ENCODING
The
Accept-Encoding header. |
static java.lang.String |
HDR_ACCEPT_RANGES
The
Accept-Ranges header. |
static java.lang.String |
HDR_AUTHORIZATION
The
Authorization header. |
static java.lang.String |
HDR_CACHE_CONTROL
The
Cache-Control header. |
static java.lang.String |
HDR_CONTENT_ENCODING
The
Content-Encoding header. |
static java.lang.String |
HDR_CONTENT_LENGTH
The
Content-Length header. |
static java.lang.String |
HDR_CONTENT_RANGE
The
Content-Range header. |
static java.lang.String |
HDR_CONTENT_TYPE
The
Content-Type header. |
static java.lang.String |
HDR_COOKIE
The
Cookie header. |
static java.lang.String |
HDR_DATE
The
Date header. |
static java.lang.String |
HDR_ETAG
The
ETag header. |
static java.lang.String |
HDR_EXPIRES
The
Expires header. |
static java.lang.String |
HDR_IF_MODIFIED_SINCE
The
If-Modified-Since header. |
static java.lang.String |
HDR_IF_NONE_MATCH
The
If-None-Match header. |
static java.lang.String |
HDR_IF_RANGE
The
If-Range header. |
static java.lang.String |
HDR_LAST_MODIFIED
The
Last-Modified header. |
static java.lang.String |
HDR_LOCATION
The
Location header. |
static java.lang.String |
HDR_PRAGMA
The
Pragma header. |
static java.lang.String |
HDR_RANGE
The
Range header. |
static java.lang.String |
HDR_SERVER
The
Server header. |
static java.lang.String |
HDR_SET_COOKIE
The
Set-Cookie header. |
static java.lang.String |
HDR_SET_COOKIE2
The
Set-Cookie2 header. |
static java.lang.String |
HDR_USER_AGENT
The
User-Agent header. |
static java.lang.String |
HDR_WWW_AUTHENTICATE
The
WWW-Authenticate header. |
private static org.slf4j.Logger |
LOG |
static java.lang.String |
METHOD_GET
The
GET HTTP method. |
static java.lang.String |
METHOD_HEAD
The
HEAD HTTP method. |
static java.lang.String |
METHOD_POST
The
POST HTTP method. |
static java.lang.String |
METHOD_PUT
The
POST HTTP method. |
static java.lang.String |
TEXT_PLAIN
The standard
text/plain MIME type. |
Modifier | Constructor and Description |
---|---|
private |
HttpSupport() |
Modifier and Type | Method and Description |
---|---|
static void |
configureTLS(javax.net.ssl.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 connection
|
static void |
encode(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.String |
getProperty(java.lang.String property) |
static java.net.Proxy |
proxyFor(java.net.ProxySelector proxySelector,
java.net.URL u)
Determine the proxy server (if any) needed to obtain a URL.
|
static int |
response(HttpConnection c)
Get the HTTP response code from the request.
|
static int |
response(java.net.HttpURLConnection c)
Get the HTTP response code from the request.
|
static java.lang.String |
responseHeader(HttpConnection c,
java.lang.String headerName)
Extract a HTTP header from the response.
|
private static final org.slf4j.Logger LOG
public static final java.lang.String METHOD_GET
GET
HTTP method.public static final java.lang.String METHOD_HEAD
HEAD
HTTP method.public static final java.lang.String METHOD_PUT
POST
HTTP method.public static final java.lang.String METHOD_POST
POST
HTTP method.public static final java.lang.String HDR_CACHE_CONTROL
Cache-Control
header.public static final java.lang.String HDR_PRAGMA
Pragma
header.public static final java.lang.String HDR_USER_AGENT
User-Agent
header.public static final java.lang.String HDR_SERVER
Server
header.public static final java.lang.String HDR_DATE
Date
header.public static final java.lang.String HDR_EXPIRES
Expires
header.public static final java.lang.String HDR_ETAG
ETag
header.public static final java.lang.String HDR_IF_NONE_MATCH
If-None-Match
header.public static final java.lang.String HDR_LAST_MODIFIED
Last-Modified
header.public static final java.lang.String HDR_IF_MODIFIED_SINCE
If-Modified-Since
header.public static final java.lang.String HDR_ACCEPT
Accept
header.public static final java.lang.String HDR_CONTENT_TYPE
Content-Type
header.public static final java.lang.String HDR_CONTENT_LENGTH
Content-Length
header.public static final java.lang.String HDR_CONTENT_ENCODING
Content-Encoding
header.public static final java.lang.String HDR_CONTENT_RANGE
Content-Range
header.public static final java.lang.String HDR_ACCEPT_RANGES
Accept-Ranges
header.public static final java.lang.String HDR_IF_RANGE
If-Range
header.public static final java.lang.String HDR_RANGE
Range
header.public static final java.lang.String HDR_ACCEPT_ENCODING
Accept-Encoding
header.public static final java.lang.String HDR_LOCATION
Location
header.public static final java.lang.String ENCODING_GZIP
gzip
encoding value for HDR_ACCEPT_ENCODING
.public static final java.lang.String ENCODING_X_GZIP
x-gzip
encoding value for HDR_ACCEPT_ENCODING
.public static final java.lang.String TEXT_PLAIN
text/plain
MIME type.public static final java.lang.String HDR_AUTHORIZATION
Authorization
header.public static final java.lang.String HDR_WWW_AUTHENTICATE
WWW-Authenticate
header.public static final java.lang.String HDR_COOKIE
Cookie
header.public static final java.lang.String HDR_SET_COOKIE
Set-Cookie
header.public static final java.lang.String HDR_SET_COOKIE2
Set-Cookie2
header.private static java.util.Set<java.lang.String> configuredHttpsProtocols
public static void encode(java.lang.StringBuilder urlstr, java.lang.String key)
urlstr
- the output buffer.key
- value which must be encoded to protected special characters.public static int response(HttpConnection c) throws java.io.IOException
Roughly the same as c.getResponseCode()
but the
ConnectException is translated to be more understandable.
c
- connection the code should be obtained from.HttpConnection
for other
defined constants.java.io.IOException
- communications error prevented obtaining the response code.public static int response(java.net.HttpURLConnection c) throws java.io.IOException
Roughly the same as c.getResponseCode()
but the
ConnectException is translated to be more understandable.
c
- connection the code should be obtained from.HttpConnection
for other
defined constants.java.io.IOException
- communications error prevented obtaining the response code.public static java.lang.String responseHeader(HttpConnection c, java.lang.String headerName) throws java.io.IOException
c
- connection the header should be obtained from.headerName
- the header namejava.io.IOException
- communications error prevented obtaining the header.public static java.net.Proxy proxyFor(java.net.ProxySelector proxySelector, java.net.URL u) throws java.net.ConnectException
proxySelector
- proxy support for the caller.u
- location of the server caller wants to talk to.java.net.ConnectException
- the proxy could not be computed as the supplied URL could not
be read. This failure should never occur.public static void disableSslVerify(HttpConnection conn) throws java.io.IOException
conn
- a HttpConnection
object.java.io.IOException
public static void configureTLS(javax.net.ssl.SSLSocket socket)
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.2 |
Supported: TLSv1, TLSV1.1, TLSv1.2 Enabled: TLSv1.2 |
socket
- to configureprivate static java.util.Set<java.lang.String> getConfiguredProtocols()
private static java.lang.String getProperty(java.lang.String property)