public final class PushBuilder extends Object
A PushBuilder is obtained by calling Request.newPushBuilder(). Each call to this method will return a new
instance of a PushBuilder based off the current HttpServletRequest. Any mutations to the returned PushBuilder are not reflected on future returns.
The instance is initialized as follows:
Request are added to the builder, except for:
Request.getRequestedSessionId() value, unless at the time of the call
Request.getSession(boolean) has previously been called to create a new Session, in which case the new
session ID will be used as the PushBuilder's requested session ID. The source of the requested session id will be the
same as for the requestRequest.getRequestURL() plus any Request.getQueryString()
Response.addCookie(Cookie) has been called on the associated response, then a corresponding Cookie
header will be added to the PushBuilder, unless the Cookie.getMaxAge() is <=0, in which case the Cookie
will be removed from the builder.
The path method must be called on the PushBuilder instance before the call to push(). Failure
to do so must cause an exception to be thrown from push(), as specified in that method.
A PushBuilder can be customized by chained calls to mutator methods before the push() method is called to
initiate an asynchronous push request with the current state of the builder. After the call to push(), the
builder may be reused for another push, however the path and conditional headers are cleared before returning from
push(). All other values are retained over calls to push().
| Constructor and Description |
|---|
PushBuilder(Request request) |
| Modifier and Type | Method and Description |
|---|---|
PushBuilder |
addHeader(org.glassfish.grizzly.http.util.Header name,
String value)
Add a request header to be used for the push.
|
PushBuilder |
addHeader(String name,
String value)
Add a request header to be used for the push.
|
String |
getHeader(String name)
Return the header of the given name to be used for the push.
|
Iterable<String> |
getHeaderNames()
Return the set of header to be used for the push.
|
String |
getMethod()
Return the method to be used for the push.
|
String |
getPath()
Return the URI path to be used for the push.
|
String |
getQueryString()
Return the query string to be used for the push.
|
String |
getSessionId()
Return the SessionID to be used for the push.
|
PushBuilder |
method(String method)
Set the method to be used for the push.
|
PushBuilder |
path(String path)
Set the URI path to be used for the push.
|
void |
push()
Push a resource given the current state of the builder without blocking.
|
PushBuilder |
queryString(String queryString)
Set the query string to be used for the push.
|
PushBuilder |
removeHeader(org.glassfish.grizzly.http.util.Header name)
Remove the named request header.
|
PushBuilder |
removeHeader(String name)
Remove the named request header.
|
PushBuilder |
sessionId(String sessionId)
Set the SessionID to be used for the push.
|
PushBuilder |
setHeader(org.glassfish.grizzly.http.util.Header name,
String value)
Set a request header to be used for the push.
|
PushBuilder |
setHeader(String name,
String value)
Set a request header to be used for the push.
|
public PushBuilder(Request request)
public PushBuilder method(String method)
Set the method to be used for the push.
method - the method to be used for the push.NullPointerException - if the argument is nullIllegalArgumentException - if the argument is the empty String, or any non-cacheable or unsafe methods defined
in RFC 7231, which are POST, PUT, DELETE, CONNECT, OPTIONS and TRACE.public PushBuilder queryString(String queryString)
Will be appended to any query String included in a call to path(String). Any duplicate parameters must be
preserved. This method should be used instead of a query in path(String) when multiple push() calls
are to be made with the same query string.
queryString - the query string to be used for the push.public PushBuilder sessionId(String sessionId)
sessionId - the SessionID to be used for the push.public PushBuilder setHeader(String name, String value)
Set a request header to be used for the push. If the builder has an existing header with the same name, its value is overwritten.
name - The header name to setvalue - The header value to setpublic PushBuilder setHeader(org.glassfish.grizzly.http.util.Header name, String value)
Set a request header to be used for the push. If the builder has an existing header with the same name, its value is overwritten.
name - The Header to setvalue - The header value to setpublic PushBuilder addHeader(String name, String value)
Add a request header to be used for the push.
name - The header name to addvalue - The header value to addpublic PushBuilder addHeader(org.glassfish.grizzly.http.util.Header name, String value)
Add a request header to be used for the push.
name - The Header to addvalue - The header value to addpublic PushBuilder removeHeader(String name)
Remove the named request header. If the header does not exist, take no action.
name - The name of the header to removepublic PushBuilder removeHeader(org.glassfish.grizzly.http.util.Header name)
Remove the named request header. If the header does not exist, take no action.
name - The Header to removepublic PushBuilder path(String path)
push(). If a query string is present in the argument
path, its contents must be merged with the contents previously passed to queryString, preserving
duplicates.path - the URI path to be used for the push, which may include a query string.public void push()
Push a resource based on the current state of the PushBuilder. Calling this method does not guarantee the resource will actually be pushed, since it is possible the client can decline acceptance of the pushed resource using the underlying HTTP/2 protocol.
Before returning from this method, the builder has its path set to null and all conditional headers removed. All other fields are left as is for possible reuse in another push.
IllegalStateException - if there was no call to path on this instance either between its instantiation
or the last call to push() that did not throw an IllegalStateException.public String getMethod()
public String getQueryString()
public String getSessionId()
public Iterable<String> getHeaderNames()
public String getHeader(String name)
public String getPath()
Copyright © 2017–2021 Oracle Corporation. All rights reserved.