Skip to content

Commit

Permalink
Enable encodeInitMessageHeaders (#6107)
Browse files Browse the repository at this point in the history
* Enable encodeInitMessageHeaders

This transitions the Firestore client from encoding HTTP Headers via the Query Param to the request's POST payload.

* Create eleven-moons-shave.md

Set the change type to 'minor'. There is no change to the public API and no feature added, but the change does require an update to the emulator. We feel that a patch may go unnoticed.

* Update firestore emulator used by tests to v1.14.4
  • Loading branch information
schmidt-sebastian committed Sep 7, 2022
1 parent 2bdbd44 commit 7c0c640
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 68 deletions.
8 changes: 8 additions & 0 deletions .changeset/eleven-moons-shave.md
@@ -0,0 +1,8 @@
---
"@firebase/firestore": minor
"@firebase/webchannel-wrapper": minor
---

Enable encodeInitMessageHeaders. This transitions the Firestore client from encoding HTTP Headers via the Query Param to the request's POST payload.

Requires Cloud Firestore Emulator v1.14.4 or newer.
32 changes: 4 additions & 28 deletions packages/firestore/src/platform/browser/webchannel_connection.ts
Expand Up @@ -15,14 +15,6 @@
* limitations under the License.
*/

import {
isBrowserExtension,
isElectron,
isIE,
isMobileCordova,
isReactNative,
isUWP
} from '@firebase/util';
import {
createWebChannelTransport,
ErrorCode,
Expand Down Expand Up @@ -215,26 +207,10 @@ export class WebChannelConnection extends RestConnection {
// https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#Simple_requests
//
// Therefore to avoid the CORS preflight request (an extra network
// roundtrip), we use the httpHeadersOverwriteParam option to specify that
// the headers should instead be encoded into a special "$httpHeaders" query
// parameter, which is recognized by the webchannel backend. This is
// formally defined here:
// https://github.com/google/closure-library/blob/b0e1815b13fb92a46d7c9b3c30de5d6a396a3245/closure/goog/net/rpc/httpcors.js#L32
//
// TODO(b/145624756): There is a backend bug where $httpHeaders isn't respected if the request
// doesn't have an Origin header. So we have to exclude a few browser environments that are
// known to (sometimes) not include an Origin. See
// https://github.com/firebase/firebase-js-sdk/issues/1491.
if (
!isMobileCordova() &&
!isReactNative() &&
!isElectron() &&
!isIE() &&
!isUWP() &&
!isBrowserExtension()
) {
request.httpHeadersOverwriteParam = '$httpHeaders';
}
// roundtrip), we use the encodeInitMessageHeaders option to specify that
// the headers should instead be encoded in the request's POST payload,
// which is recognized by the webchannel backend.
request.encodeInitMessageHeaders = true;

const url = urlParts.join('');
logDebug(LOG_TAG, 'Creating WebChannel: ' + url, request);
Expand Down
4 changes: 2 additions & 2 deletions packages/webchannel-wrapper/externs/overrides.js
Expand Up @@ -51,8 +51,8 @@ goog.net.WebChannel.Options.sendRawJson;
/** @type {string|undefined} */
goog.net.WebChannel.Options.httpSessionIdParam;

/** @type {string|undefined} */
goog.net.WebChannel.Options.httpHeadersOverwriteParam;
/** @type {boolean|undefined} */
goog.net.WebChannel.Options.encodeInitMessageHeaders;

/** @type {boolean|undefined} */
goog.net.WebChannel.Options.fastHandshake;
Expand Down
5 changes: 3 additions & 2 deletions packages/webchannel-wrapper/package.json
Expand Up @@ -26,8 +26,9 @@
},
"license": "Apache-2.0",
"devDependencies": {
"google-closure-compiler": "20210601.0.0",
"google-closure-library": "20210406.0.0",
"@rollup/plugin-commonjs": "21.0.0",
"google-closure-compiler": "20220301.0.0",
"google-closure-library": "20220301.0.0",
"gulp": "4.0.2",
"gulp-sourcemaps": "3.0.0",
"rollup": "2.72.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/webchannel-wrapper/src/index.d.ts
Expand Up @@ -96,7 +96,7 @@ export interface WebChannelOptions {
supportsCrossDomainXhr?: boolean;
sendRawJson?: boolean;
httpSessionIdParam?: string;
httpHeadersOverwriteParam?: string;
encodeInitMessageHeaders?: boolean;
forceLongPolling?: boolean;
detectBufferingProxy?: boolean;
fastHandshake?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions scripts/emulator-testing/emulators/firestore-emulator.ts
Expand Up @@ -22,11 +22,11 @@ export class FirestoreEmulator extends Emulator {

constructor(port: number, projectId = 'test-emulator') {
super(
'cloud-firestore-emulator-v1.11.7.jar',
'cloud-firestore-emulator-v1.14.4.jar',
// Use locked version of emulator for test to be deterministic.
// The latest version can be found from firestore emulator doc:
// https://firebase.google.com/docs/firestore/security/test-rules-emulator
'https://storage.googleapis.com/firebase-preview-drop/emulator/cloud-firestore-emulator-v1.11.7.jar',
'https://storage.googleapis.com/firebase-preview-drop/emulator/cloud-firestore-emulator-v1.14.4.jar',
port
);
this.projectId = projectId;
Expand Down
66 changes: 33 additions & 33 deletions yarn.lock
Expand Up @@ -8869,45 +8869,45 @@ google-auth-library@^8.0.2:
jws "^4.0.0"
lru-cache "^6.0.0"

google-closure-compiler-java@^20210601.0.0:
version "20210601.0.0"
resolved "https://registry.npmjs.org/google-closure-compiler-java/-/google-closure-compiler-java-20210601.0.0.tgz#88dc11b334bee6a704d9674c5143fd2e0d553517"
integrity sha512-bH6nIwOmp4qDWvlbXx5/DE3XA2aDGQoCpmRYZJGONY1Sy6Xfbq0ioXRHH9eBDP9hxhCJ5Sd/K89A0NZ8Nz9RJA==

google-closure-compiler-linux@^20210601.0.0:
version "20210601.0.0"
resolved "https://registry.npmjs.org/google-closure-compiler-linux/-/google-closure-compiler-linux-20210601.0.0.tgz#6e5dd7b00b96dc1fd1ba30e3401af85558768322"
integrity sha512-rnEQt7zz/1P1SfPhJiHQpfCgMPrsVVyEgDs09h67xn6+LXa9L0RP+hrJDEHqSWwjDPz0BkfUUv6zkqZvp1h/lw==

google-closure-compiler-osx@^20210601.0.0:
version "20210601.0.0"
resolved "https://registry.npmjs.org/google-closure-compiler-osx/-/google-closure-compiler-osx-20210601.0.0.tgz#e23356bc9ef6e68c2980f60a207f603767b50b21"
integrity sha512-A5r4s/WthR2iLMM0mxsluw8EW2AcOomC5ri/H6FjzpMq0RVEnLTgaGYdXolUAfEzH/7XtJJT2+JkYk3HSLCtrg==

google-closure-compiler-windows@^20210601.0.0:
version "20210601.0.0"
resolved "https://registry.npmjs.org/google-closure-compiler-windows/-/google-closure-compiler-windows-20210601.0.0.tgz#b5400d06bbf0bbd2602ee3ae0c2bc7ebd5829692"
integrity sha512-6r94bPShnB0XXh9+5/qXGDHJN2PQGhF9yJPcgBZj+FAZlQGzlYkT0pkyp+loZT3lG+YRbjD28Lgo7xMcY4xgkA==

google-closure-compiler@20210601.0.0:
version "20210601.0.0"
resolved "https://registry.npmjs.org/google-closure-compiler/-/google-closure-compiler-20210601.0.0.tgz#34597c33c9285ebd3a5364f5299f6c9ddc9fc88a"
integrity sha512-lzzEoG2VTB7uUjnWnMyeZMU163w69HJpM27yh8Up9Ha5McHZeESjt3NRwU8cWMbCRdY06nFbRCDIVCRcadHCiw==
google-closure-compiler-java@^20220301.0.0:
version "20220301.0.0"
resolved "https://registry.npmjs.org/google-closure-compiler-java/-/google-closure-compiler-java-20220301.0.0.tgz#6283bad6991ae9cfb3a9fdf72bbd7bf0c8f21fb6"
integrity sha512-kv5oaUI4xn3qWYWtRHRqbm314kesfeFlCxiFRcvBIx13mKfR0qvbOkgajLpSM6nb3voNM/E9MB9mfvHJ9XIXSg==

google-closure-compiler-linux@^20220301.0.0:
version "20220301.0.0"
resolved "https://registry.npmjs.org/google-closure-compiler-linux/-/google-closure-compiler-linux-20220301.0.0.tgz#3ac8cd1cb51d703a89bc49c239df4c10b57f37bb"
integrity sha512-N2D0SRnxZ7kqdoZ2WsmLIjmizR4Xr0HaUYDK2RCOtsV21RYV8OR2u0ATp7aXhYy8WfxvYH478Ehvmc9Uzy986A==

google-closure-compiler-osx@^20220301.0.0:
version "20220301.0.0"
resolved "https://registry.npmjs.org/google-closure-compiler-osx/-/google-closure-compiler-osx-20220301.0.0.tgz#1a49eb1d78b6bfb90ebe51c24a7151cee4f319a3"
integrity sha512-Xqf0m5takwfv43ML4aODJxmAsAZQMTMo683gyRs0APAecncs+YKxaDPMH+pQAdI3HPY2QsvkarlunAp0HSwU5A==

google-closure-compiler-windows@^20220301.0.0:
version "20220301.0.0"
resolved "https://registry.npmjs.org/google-closure-compiler-windows/-/google-closure-compiler-windows-20220301.0.0.tgz#b09df91a789e458eb9ebf054a9bb2d2b29622b6f"
integrity sha512-s+FU/vcpLTEgx8MCMgj0STCYkVk7syzF9KqiYPOTtbTD9ra99HPe/CEuQG7iJ3Fty9dhm9zEaetv4Dp4Wr6x+Q==

google-closure-compiler@20220301.0.0:
version "20220301.0.0"
resolved "https://registry.npmjs.org/google-closure-compiler/-/google-closure-compiler-20220301.0.0.tgz#1c4f56076ae5b2c900a91d0a72515f7ee7f5d3cd"
integrity sha512-+yAqhufKIWddg587tnvRll92eLJQIlzINmgr1h5gLXZVioY3svrSYKH4TZiUuNj0UnVFoK0o1YuW122x+iFl2g==
dependencies:
chalk "2.x"
google-closure-compiler-java "^20210601.0.0"
google-closure-compiler-java "^20220301.0.0"
minimist "1.x"
vinyl "2.x"
vinyl-sourcemaps-apply "^0.2.0"
optionalDependencies:
google-closure-compiler-linux "^20210601.0.0"
google-closure-compiler-osx "^20210601.0.0"
google-closure-compiler-windows "^20210601.0.0"

google-closure-library@20210406.0.0:
version "20210406.0.0"
resolved "https://registry.npmjs.org/google-closure-library/-/google-closure-library-20210406.0.0.tgz#47d6036c1704661ad47cde2e35f19cc55e33e775"
integrity sha512-1lAC/KC9R2QM6nygniM0pRcGrv5bkCUrIZb2hXFxLtAkA+zRiVeWtRYpFWDHXXJzkavKjsn9upiffL4x/nmmVg==
google-closure-compiler-linux "^20220301.0.0"
google-closure-compiler-osx "^20220301.0.0"
google-closure-compiler-windows "^20220301.0.0"

google-closure-library@20220301.0.0:
version "20220301.0.0"
resolved "https://registry.npmjs.org/google-closure-library/-/google-closure-library-20220301.0.0.tgz#c9aaa99218f949b1f914a86f2a4529dea20e2e47"
integrity sha512-GRRBfG80JPqkKkTxiRoVr/x4UmnPW2aeA72NH0zapPtrvSkAOCzfJFrdudLrAJJtXPdSE65+CkYrpZX8tP0mCQ==

google-gax@^3.0.1:
version "3.1.3"
Expand Down

0 comments on commit 7c0c640

Please sign in to comment.