File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -118,6 +118,41 @@ socket.on('open', () => {
118
118
});
119
119
` ` `
120
120
121
+ In the browser, the [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) object does not support additional headers.
122
+ In case you want to add some headers as part of some authentication mechanism, you can use the ` transportOptions` attribute.
123
+ Please note that in this case the headers won' t be sent in the WebSocket upgrade request.
124
+
125
+ ```js
126
+ // WILL NOT WORK in the browser
127
+ require(' engine.io-client' )(' http://localhost' , {
128
+ extraHeaders: {
129
+ ' X-Custom-Header-For-My-Project' : ' will not be sent'
130
+ }
131
+ });
132
+ // WILL NOT WORK
133
+ require(' engine.io-client' )(' http://localhost' , {
134
+ transports: [' websocket' ], // polling is disabled
135
+ transportOptions: {
136
+ polling: {
137
+ extraHeaders: {
138
+ ' X-Custom-Header-For-My-Project' : ' will not be sent'
139
+ }
140
+ }
141
+ }
142
+ });
143
+ // WILL WORK
144
+ require(' engine.io-client' )(' http://localhost' , {
145
+ transports: [' polling' , ' websocket' ],
146
+ transportOptions: {
147
+ polling: {
148
+ extraHeaders: {
149
+ ' X-Custom-Header-For-My-Project' : ' will be used'
150
+ }
151
+ }
152
+ }
153
+ });
154
+ ```
155
+
121
156
## Features
122
157
123
158
- Lightweight
You can’t perform that action at this time.
0 commit comments