Skip to content
This repository was archived by the owner on Mar 20, 2021. It is now read-only.

Commit da7314a

Browse files
committed
[2.3.x] Changes for GRIZZLY-1886.
- Expose server push configuration via Http2Connection and Http2Stream.
1 parent 916e72f commit da7314a

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

modules/http2/src/main/java/org/glassfish/grizzly/http2/Http2BaseFilter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ void applySettings(final Http2Connection http2Connection,
645645
case SettingsFrame.SETTINGS_HEADER_TABLE_SIZE:
646646
break;
647647
case SettingsFrame.SETTINGS_ENABLE_PUSH:
648+
http2Connection.setPushEnabled(setting.getValue() == 1);
648649
break;
649650
case SettingsFrame.SETTINGS_MAX_CONCURRENT_STREAMS:
650651
http2Connection.setPeerMaxConcurrentStreams(setting.getValue());

modules/http2/src/main/java/org/glassfish/grizzly/http2/Http2Connection.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public class Http2Connection {
117117

118118
private int lastPeerStreamId;
119119
private int lastLocalStreamId;
120+
private boolean pushEnabled = true;
120121

121122
private final ReentrantLock newClientStreamLock = new ReentrantLock();
122123

@@ -551,6 +552,23 @@ void setPeerMaxConcurrentStreams(int peerMaxConcurrentStreams) {
551552
this.peerMaxConcurrentStreams = peerMaxConcurrentStreams;
552553
}
553554

555+
/**
556+
* @return <code>true</code> if push is enabled for this {@link Http2Connection}, otherwise
557+
* returns <code>false</code>. Push is enabled by default.
558+
*/
559+
public boolean isPushEnabled() {
560+
return pushEnabled;
561+
}
562+
563+
/**
564+
* Configure whether or not push is enabled on this {@link Http2Connection}.
565+
*
566+
* @param pushEnabled flag toggling push support.
567+
*/
568+
public void setPushEnabled(final boolean pushEnabled) {
569+
this.pushEnabled = pushEnabled;
570+
}
571+
554572

555573
public int getNextLocalStreamId() {
556574
lastLocalStreamId += 2;

modules/http2/src/main/java/org/glassfish/grizzly/http2/Http2Stream.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,24 +248,33 @@ public HttpRequestPacket getRequest() {
248248
public HttpResponsePacket getResponse() {
249249
return request.getResponse();
250250
}
251+
252+
public boolean isPushEnabled() {
253+
return http2Connection.isPushEnabled();
254+
}
251255

252256
public PushResource addPushResource(final String url,
253257
final PushResource pushResource) {
254-
255-
if (associatedResourcesToPush == null) {
256-
associatedResourcesToPush = new HashMap<>();
258+
if (isPushEnabled()) {
259+
if (associatedResourcesToPush == null) {
260+
associatedResourcesToPush = new HashMap<>();
261+
}
262+
263+
return associatedResourcesToPush.put(url, pushResource);
257264
}
258-
259-
return associatedResourcesToPush.put(url, pushResource);
265+
return null;
260266
}
261267

262268
public PushResource removePushResource(final String url) {
263-
264-
if (associatedResourcesToPush == null) {
265-
return null;
269+
270+
if (isPushEnabled()) {
271+
if (associatedResourcesToPush == null) {
272+
return null;
273+
}
274+
275+
return associatedResourcesToPush.remove(url);
266276
}
267-
268-
return associatedResourcesToPush.remove(url);
277+
return null;
269278
}
270279

271280
public int getId() {

0 commit comments

Comments
 (0)