Skip to content
This repository was archived by the owner on Aug 1, 2024. It is now read-only.

Commit 96278c1

Browse files
Closure Teamcopybara-github
authored andcommitted
Adds a new API setIsBuffered to allow clients to set connection status. This can be used by clients that perform additional tests to determine if a connection is actually buffered or not after initial load.
RELNOTES: Adds a new API setIsBuffered to allow clients to set connection status PiperOrigin-RevId: 518289912 Change-Id: Iab16a025ef72c545f572fe4aa4e5689011a9447d
1 parent f1959de commit 96278c1

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

closure/goog/net/browserchannel.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,24 @@ goog.net.BrowserChannel.prototype.isBuffered = function() {
10271027
};
10281028

10291029

1030+
/**
1031+
* Sets whether the channel is buffered or not. This state is usually updated in
1032+
* goog.net.BrowserChannel.testConnectionFinished, but can be set manually here.
1033+
* This updated status will be reflected in subsequent connections and requests
1034+
* to the channel.
1035+
* NOTE: This should ONLY be used by clients that are certain of their
1036+
* connection status, i.e. that have performed additional test channels. Setting
1037+
* the wrong buffered status on a client can result in undeliverable responses
1038+
* from the server.
1039+
* @param {boolean} isBuffered Whether the channel is buffered.
1040+
*/
1041+
goog.net.BrowserChannel.prototype.setIsBuffered = function(isBuffered) {
1042+
'use strict';
1043+
this.useChunked_ = !isBuffered;
1044+
this.secondTestResults_ = isBuffered;
1045+
};
1046+
1047+
10301048
/**
10311049
* Returns whether chunked mode is allowed. In certain debugging situations,
10321050
* it's useful for the application to have a way to disable chunked mode for a
@@ -1652,7 +1670,14 @@ goog.net.BrowserChannel.prototype.testConnectionFinished = function(
16521670
'use strict';
16531671
this.channelDebug_.debug('Test Connection Finished');
16541672

1655-
this.useChunked_ = this.allowChunkedMode_ && useChunked;
1673+
// Use the results of the second phase of the test channel if user decided to
1674+
// override the test results while the test was ongoing.
1675+
if (this.secondTestResults_ == null) {
1676+
this.useChunked_ = this.allowChunkedMode_ && useChunked;
1677+
} else {
1678+
this.useChunked_ = !this.secondTestResults_;
1679+
}
1680+
16561681
this.lastStatusCode_ = testChannel.getLastStatusCode();
16571682
// When using asynchronous test, the channel is already open by connect().
16581683
if (!this.asyncTest_) {

closure/goog/net/browserchannel_test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,9 @@ testSuite({
406406

407407
numStatEvents = 0;
408408
lastStatEvent = null;
409+
410+
/** @suppress {visibility} suppression added to enable type checking */
411+
browserChannel.asyncTest_ = false;
409412
},
410413

411414
tearDown() {
@@ -1317,4 +1320,25 @@ testSuite({
13171320
'0',
13181321
browserChannel.backChannelRequest_.requestUri_.queryData_.get('CI'));
13191322
},
1323+
1324+
/** @suppress {visibility} suppression added to enable type checking */
1325+
testSetIsBuffered() {
1326+
connect();
1327+
browserChannel.setIsBuffered(true);
1328+
completeBackChannel();
1329+
browserChannel.setIsBuffered(false);
1330+
1331+
// Back channel will still be buffered, because #setIsBuffered was called
1332+
// after the back channel was already open.
1333+
assertEquals(
1334+
'1',
1335+
browserChannel.backChannelRequest_.requestUri_.queryData_.get('CI'));
1336+
1337+
// Subsequent back channels that are opened will be streaming.
1338+
completeBackChannel();
1339+
assertFalse(browserChannel.isBuffered());
1340+
assertEquals(
1341+
'0',
1342+
browserChannel.backChannelRequest_.requestUri_.queryData_.get('CI'));
1343+
},
13201344
});

0 commit comments

Comments
 (0)