From 4ff290f09f572b0b174f29920577df35900b4df1 Mon Sep 17 00:00:00 2001 From: Alexander Emelin Date: Sun, 12 Jan 2025 19:44:37 +0200 Subject: [PATCH] Headers emulation (#299) --- src/centrifuge.ts | 9 +++++++++ src/client.proto.json | 9 +++++++++ src/types.ts | 5 +++++ 3 files changed, 23 insertions(+) diff --git a/src/centrifuge.ts b/src/centrifuge.ts index d1e6b59c..62789f5a 100644 --- a/src/centrifuge.ts +++ b/src/centrifuge.ts @@ -28,6 +28,7 @@ import { import EventEmitter from 'events'; const defaults: Options = { + headers: {}, token: '', getToken: null, data: null, @@ -250,6 +251,11 @@ export class Centrifuge extends (EventEmitter as new () => TypedEventEmitter { @@ -1045,6 +1051,9 @@ export class Centrifuge extends (EventEmitter as new () => TypedEventEmitter 0) { + req.headers = this._config.headers; + } const subs = {}; let hasSubs = false; diff --git a/src/client.proto.json b/src/client.proto.json index c87a5f34..c3fd47fd 100644 --- a/src/client.proto.json +++ b/src/client.proto.json @@ -273,6 +273,10 @@ "time": { "type": "int64", "id": 9 + }, + "channel": { + "type": "string", + "id": 10 } }, "reserved": [ @@ -465,6 +469,11 @@ "version": { "type": "string", "id": 5 + }, + "headers": { + "keyType": "string", + "type": "string", + "id": 6 } } }, diff --git a/src/types.ts b/src/types.ts index 77220f4f..dda6a873 100644 --- a/src/types.ts +++ b/src/types.ts @@ -91,6 +91,11 @@ export interface TransportEndpoint { /** Options for Centrifuge client. */ export interface Options { + // provide header emulation, these headers are sent with first protocol message + // the backend can process those in a customized manner. In case of Centrifugo + // these headers are then used like real HTTP headers sent from the client. + // Requires Centrifugo v6. + headers: {[key: string]: string}; /** allows enabling debug mode */ debug: boolean; /** allows setting initial connection token (JWT) */