From ecea635b8372cd14c7bd846e84b6ab1c7fc7e008 Mon Sep 17 00:00:00 2001 From: FZambia Date: Fri, 15 Nov 2024 08:39:30 +0200 Subject: [PATCH 1/2] headers emulation --- src/centrifuge.ts | 9 +++++++++ src/client.proto.json | 9 +++++++++ src/types.ts | 4 ++++ 3 files changed, 22 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..3e5b7d00 100644 --- a/src/types.ts +++ b/src/types.ts @@ -91,6 +91,10 @@ 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. + headers: {[key: string]: string}; /** allows enabling debug mode */ debug: boolean; /** allows setting initial connection token (JWT) */ From 90d6ad3ff0872d08695e28a000c39a70ba824a4b Mon Sep 17 00:00:00 2001 From: FZambia Date: Sun, 12 Jan 2025 19:40:51 +0200 Subject: [PATCH 2/2] better comment --- src/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/types.ts b/src/types.ts index 3e5b7d00..dda6a873 100644 --- a/src/types.ts +++ b/src/types.ts @@ -94,6 +94,7 @@ 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;