Interface PushCapableHttpRequest<B>
- Type Parameters:
B
- The Http message body
- All Superinterfaces:
AttributeHolder
,HttpMessage<B>
,HttpRequest<B>
,MutableAttributeHolder
- All Known Implementing Classes:
NettyHttpRequest
HttpRequest
that is potentially capable of HTTP2 server push. Code should check
isServerPushSupported()
before attempting to send any server push.- Since:
- 3.2
- Author:
- Jonas Konrad
-
Field Summary
Fields inherited from interface io.micronaut.http.HttpRequest
SCHEME_HTTP, SCHEME_HTTPS
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Check whether HTTP2 server push is supported by the remote client.serverPush
(@NonNull HttpRequest<?> request) Initiate a HTTP2 server push for the given request.Methods inherited from interface io.micronaut.core.attr.AttributeHolder
getAttribute, getAttribute
Methods inherited from interface io.micronaut.http.HttpMessage
getAttributes, getBody, getBody, getBody, getBody, getBodyWriter, getCharacterEncoding, getContentLength, getContentType, getHeaders
Methods inherited from interface io.micronaut.http.HttpRequest
accept, getCertificate, getCookies, getHttpVersion, getLocale, getMethod, getMethodName, getOrigin, getParameters, getPath, getRemoteAddress, getServerAddress, getServerName, getUri, getUserPrincipal, getUserPrincipal, isSecure, mutate, setAttribute
Methods inherited from interface io.micronaut.core.attr.MutableAttributeHolder
removeAttribute
-
Method Details
-
isServerPushSupported
boolean isServerPushSupported()Check whether HTTP2 server push is supported by the remote client. Only HTTP2 clients that indicate support through HTTP2 settings have this method returntrue
.- Returns:
true
iff server push is supported.
-
serverPush
Initiate a HTTP2 server push for the given request. The information from the given request (i.e. path, headers) will be passed on to the client immediately so that it does not send the request itself. Then, the given request will be handled as if it was initiated by the client, and the response will be passed back to the client.
This method mostly follows the semantics of JavaEE
javax.servlet.http.PushBuilder
. This means most of the headers of this request are copied into the push request, and the referer is set. To override this behavior, add a corresponding header to therequest
passed as the parameter of this method: those headers take precedence.Security note: The
Authorization
header and other headers not excluded by the above paragraph will be copied and sent to the client as part of a HTTP2PUSH_PROMISE
. Normally, this is fine, because the client sent those headers in the first place. But if there is an intermediate proxy that added a header, this header may then leak to the client.- Parameters:
request
- The request to respond to using a server push.- Returns:
- This request.
- Throws:
UnsupportedOperationException
- if the client does not support server push. Check beforehand usingisServerPushSupported()
.
-