-
Notifications
You must be signed in to change notification settings - Fork 19
/
IdentityProxyServiceWorker.js
48 lines (41 loc) · 1.83 KB
/
IdentityProxyServiceWorker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(function () {
"use strict";
var IdentityProxyCore = require("./IdentityProxyCore"),
IdentityProxyServiceWorker = function () {
return IdentityProxyCore.apply(this, arguments);
};
IdentityProxyServiceWorker.prototype = Object.create(IdentityProxyCore.prototype);
IdentityProxyServiceWorker.prototype.serializeHeaders = function (headers) {
let headersObj = {};
for (let key of headers.keys()) {
headersObj[key] = headers.get(key);
}
return headersObj;
};
IdentityProxyServiceWorker.prototype.serializeRequest = function (request) {
return new Promise((resolve) => {
request.clone().blob()
.then((bodyBlob) => this.fixupBlobContentType(bodyBlob))
.then((bodyBlob) =>
resolve({
url: request.url,
options: {
method: request.method,
headers: this.serializeHeaders(request.headers),
body: ["GET","HEAD"].indexOf(request.method.toUpperCase()) === -1 && bodyBlob && bodyBlob.size ? bodyBlob : undefined,
mode: request.mode,
credentials: request.credentials,
cache: request.cache,
redirect: request.redirect,
referrer: request.referrer,
integrity: request.integrity
}
})
);
});
};
IdentityProxyServiceWorker.prototype.deserializeResponse = function (serializedResponse) {
return Promise.resolve(new Response(serializedResponse.body, serializedResponse.init));
};
module.exports = IdentityProxyServiceWorker;
}());