Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/firestore/src/platform/browser/webchannel_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
WebChannelError,
WebChannelOptions,
FetchXmlHttpFactory,
Md5,
XhrIo,
getStatEventTarget,
EventTarget,
Expand Down Expand Up @@ -95,12 +96,20 @@ export class WebChannelConnection extends RestConnection {
break;
case ErrorCode.HTTP_ERROR:
const status = xhr.getStatus();

const md5 = new Md5();
md5.update([1, 2, 3, 4]);
md5.reset();
md5.update([4, 3, 2, 1]);
const value = md5.digest();

logDebug(
LOG_TAG,
`RPC '${rpcName}' ${streamId} failed with status:`,
status,
'response text:',
xhr.getResponseText()
xhr.getResponseText(),
`${value}`
);
if (status > 0) {
let response = xhr.getResponseJson();
Expand Down
9 changes: 9 additions & 0 deletions packages/webchannel-wrapper/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,12 @@ export function getStatEventTarget(): EventTarget;
export class FetchXmlHttpFactory {
constructor(options: {});
}

// See https://google.github.io/closure-library/api/goog.crypt.Md5.html
// Unit test are written in
// packages/firestore/test/unit/core/webchannel_wrapper.test.ts
export class Md5 {
reset(): void;
digest(): Array<number>;
update(bytes: Array<number> | Uint8Array | string, opt_length?: number): void;
}
6 changes: 6 additions & 0 deletions packages/webchannel-wrapper/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ goog.net.XhrIo.prototype['send'] = goog.net.XhrIo.prototype.send;
goog.net.XhrIo.prototype['setWithCredentials'] =
goog.net.XhrIo.prototype.setWithCredentials;

goog.require('goog.crypt.Md5');
goog.crypt.Md5.prototype['digest'] = goog.crypt.Md5.prototype.digest;
goog.crypt.Md5.prototype['reset'] = goog.crypt.Md5.prototype.reset;
goog.crypt.Md5.prototype['update'] = goog.crypt.Md5.prototype.update;

module['exports']['createWebChannelTransport'] =
goog.net.createWebChannelTransport;
module['exports']['getStatEventTarget'] =
Expand All @@ -89,3 +94,4 @@ module['exports']['Stat'] = goog.labs.net.webChannel.requestStats.Stat;
module['exports']['FetchXmlHttpFactory'] = goog.net.FetchXmlHttpFactory;
module['exports']['WebChannel'] = goog.net.WebChannel;
module['exports']['XhrIo'] = goog.net.XhrIo;
module['exports']['Md5'] = goog.crypt.Md5;