wechaty-puppet-service
Version:
Puppet Service for Wechaty
32 lines • 1.31 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.monkeyPatchMetadataFromHttp2Headers = void 0;
const wechaty_puppet_1 = require("wechaty-puppet");
/**
* Huan(202108): This is for compatible with old clients (version v0.26 or before)
* for non-tls authorization:
* use the HTTP2 header `:authority` as the token.
*
* This feature is planed to be removed after Dec 31, 2022
*/
function monkeyPatchMetadataFromHttp2Headers(MetadataClass) {
wechaty_puppet_1.log.verbose('wechaty-puppet-service', 'monkeyPatchMetadataFromHttp2Headers()');
const fromHttp2Headers = MetadataClass.fromHttp2Headers;
MetadataClass.fromHttp2Headers = function (headers) {
const metadata = fromHttp2Headers.call(MetadataClass, headers);
if (metadata.get('authorization').length <= 0) {
const authority = headers[':authority'];
const authorization = `Wechaty ${authority}`;
metadata.set('authorization', authorization);
}
return metadata;
};
/**
* un-monkey-patch
*/
return () => {
MetadataClass.fromHttp2Headers = fromHttp2Headers;
};
}
exports.monkeyPatchMetadataFromHttp2Headers = monkeyPatchMetadataFromHttp2Headers;
//# sourceMappingURL=mokey-patch-header-authorization.js.map
;