Skip to content

Commit d8ff579

Browse files
committed
Fix jakartaee#538 - Make HTTP/2 push support optional
1 parent 6475d9b commit d8ff579

File tree

4 files changed

+59
-37
lines changed

4 files changed

+59
-37
lines changed

api/src/main/java/jakarta/servlet/http/HttpServletRequest.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,15 @@ public String toString() {
288288
*
289289
* @implSpec The default implementation returns null.
290290
*
291-
* @return a {@link PushBuilder} for issuing server push responses from the current request, or null if push is not
292-
* supported
291+
* @return a {@link PushBuilder} for issuing server push responses from the current request, or {@code null} if push is
292+
* not supported. Note that some implementations may opt not to support server push and will therefore always return
293+
* {@code null}
293294
*
294295
* @since Servlet 4.0
296+
*
297+
* @deprecated Use early hints via TBD instead
295298
*/
299+
@Deprecated
296300
default public PushBuilder newPushBuilder() {
297301
return null;
298302
}

api/src/main/java/jakarta/servlet/http/HttpServletRequestWrapper.java

+3
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,10 @@ public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IO
331331
* The default behavior of this method is to call newPushBuilder on the wrapped request object.
332332
*
333333
* @since Servlet 4.0
334+
*
335+
* @deprecated Use early hints via TBD instead
334336
*/
337+
@Deprecated
335338
@Override
336339
public PushBuilder newPushBuilder() {
337340
return this._getHttpServletRequest().newPushBuilder();

api/src/main/java/jakarta/servlet/http/PushBuilder.java

+3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@
8383
* are retained over calls to {@link #push()}.
8484
*
8585
* @since Servlet 4.0
86+
*
87+
* @deprecated Use early hints via TBD instead
8688
*/
89+
@Deprecated
8790
public interface PushBuilder {
8891
/**
8992
* <p>

spec/src/main/asciidoc/servlet-spec-body.adoc

+47-35
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ Requirement Levels
138138

139139
* RFC 7617 The 'Basic' HTTP Authentication Scheme
140140

141+
* RFC 8297 An HTTP Status Code for Indicating Hints
142+
141143
* RFC 9110 HTTP Semantics
142144

143145
* RFC 9111 HTTP Caching
@@ -1655,43 +1657,49 @@ thrown.
16551657

16561658
=== HTTP/2 Server Push
16571659

1658-
Server push is the most visible of the
1659-
improvements in HTTP/2 to appear in the servlet API. All of the new
1660-
features in HTTP/2, including server push, are aimed at improving the
1661-
perceived performance of the web browsing experience. Server push
1662-
derives its contribution to improved perceived browser performance from
1663-
the simple fact that servers are in a much better position than clients
1664-
to know what additional assets (such as images, stylesheets and scripts)
1665-
go along with initial requests. For example, it is possible for servers
1666-
to know that whenever a browser requests `index.html`, it will shortly
1667-
thereafter request `header.gif`, `footer.gif` and `style.css`. Since
1668-
servers know this, they can preemptively start sending the bytes of
1669-
these assets along side the bytes of the `index.html`.
1670-
1671-
To use server push, obtain a reference to a
1672-
`PushBuilder` from an `HttpServletRequest`, mutate the builder as
1673-
desired, then call `push()`. Please see the javadoc for method
1660+
Server push was intended to improve the perceived performance of the web
1661+
browsing experience. The basis for this was the idea that servers are in a much
1662+
better position than clients to know what additional assets (such as images,
1663+
stylesheets and scripts) go along with initial requests. For example, it is
1664+
possible for servers to know that whenever a browser requests `index.html`, it
1665+
will shortly require `header.gif`, `footer.gif` and `style.css`. Since servers
1666+
know this, they can preemptively start sending the bytes of these assets along
1667+
side the bytes of the `index.html`.
1668+
1669+
Server push has not been widely adopted and the leading browsers have removed
1670+
support for server push. This is because the server does not have visibility
1671+
into either the client cache or any intermediate caches that may be present and,
1672+
as such, is unable to identify which resources need to be pushed and which the
1673+
client already has. Server push has essentially been replaced by RFC 8297 (Early
1674+
Hints).
1675+
1676+
Server push support was added in version 4 of this specification. As of version
1677+
6.1 of this specification, containers are not required to support server push
1678+
and may always return `null` from
1679+
`jakarta.servlet.http.HttpServletRequest.newPushBuilder()`
1680+
1681+
To use server push, obtain a reference to a `PushBuilder` from an
1682+
`HttpServletRequest`, mutate the builder as desired, then call `push()`. Please
1683+
see the javadoc for method
16741684
`jakarta.servlet.http.HttpServletRequest.newPushBuilder()` and class
16751685
`jakarta.servlet.http.PushBuilder` for the normative specification. The
1676-
remainder of this section calls out implementation requirements with
1677-
respect to the section titled “Server Push” in the HTTP/2 specification
1678-
version referenced in <<Other Important References>>.
1679-
1680-
Unless explicitly excluded, Servlet {spec-version}
1681-
containers must support server push as specified in the HTTP/2
1682-
specification section “Server Push”. Containers must enable server push
1683-
if the client is capable of speaking HTTP/2, unless the client has
1684-
explicitly disabled server push by sending a `SETTINGS_ENABLE_PUSH`
1685-
setting value of 0 (zero) for the current connection. In that case, for
1686-
that connection only, server push must not be enabled.
1687-
1688-
In addition to allowing clients to disable
1689-
server push with the `SETTINGS_ENABLE_PUSH` setting, servlet containers
1690-
must honor a client’s request to not receive a pushed response on a
1691-
finer grained basis by heeding the `CANCEL` or `REFUSED_STREAM` code
1692-
that references the pushed stream’s stream identifier. One common use of
1693-
this interaction is when a browser already has the resource in its
1694-
cache.
1686+
remainder of this section calls out implementation requirements with respect to
1687+
the section titled “Server Push” in the HTTP/2 specification version referenced
1688+
in <<Other Important References>>.
1689+
1690+
Servlet {spec-version} containers may support server push as specified in the
1691+
HTTP/2 specification section “Server Push”. Containers may enable server push if
1692+
the client is capable of speaking HTTP/2, unless the client has explicitly
1693+
disabled server push by sending a `SETTINGS_ENABLE_PUSH` setting value of 0
1694+
(zero) for the current connection. In that case, for that connection only,
1695+
server push must not be enabled.
1696+
1697+
In addition to allowing clients to disable server push with the
1698+
`SETTINGS_ENABLE_PUSH` setting, servlet containers must honor a client’s request
1699+
to not receive a pushed response on a finer grained basis by heeding the
1700+
`CANCEL` or `REFUSED_STREAM` code that references the pushed stream’s stream
1701+
identifier. One common use of this interaction is when a browser already has the
1702+
resource in its cache.
16951703

16961704
=== Cookies
16971705

@@ -8648,6 +8656,10 @@ Add ByteBuffer support to `ServletInputStream` and `ServletOutputStream`.
86488656
Clarify the expected behavior if the container receives an HTTP request using
86498657
the `CONNECT` method.
86508658

8659+
link:https://github.com/eclipse-ee4j/servlet-api/issues/538[Issue 538]::
8660+
Deprecate support for HTTP/2 server push and make implementaing support for this
8661+
feature optional.
8662+
86518663
=== Changes Since Jakarta Servlet 5.0
86528664

86538665
The minimum Java version has been increased to Java 11.

0 commit comments

Comments
 (0)