@@ -3,7 +3,11 @@ import debugModule from "debug"; // debug()
3
3
import { yeast } from "../contrib/yeast.js" ;
4
4
import { encode } from "../contrib/parseqs.js" ;
5
5
import { encodePayload , decodePayload , RawData } from "engine.io-parser" ;
6
- import { XHR as XMLHttpRequest } from "./xmlhttprequest.js" ;
6
+ import {
7
+ CookieJar ,
8
+ createCookieJar ,
9
+ XHR as XMLHttpRequest ,
10
+ } from "./xmlhttprequest.js" ;
7
11
import { Emitter } from "@socket.io/component-emitter" ;
8
12
import { SocketOptions } from "../socket.js" ;
9
13
import { installTimerFunctions , pick } from "../util.js" ;
@@ -26,6 +30,7 @@ export class Polling extends Transport {
26
30
27
31
private polling : boolean = false ;
28
32
private pollXhr : any ;
33
+ private cookieJar ?: CookieJar ;
29
34
30
35
/**
31
36
* XHR Polling constructor.
@@ -56,6 +61,10 @@ export class Polling extends Transport {
56
61
*/
57
62
const forceBase64 = opts && opts . forceBase64 ;
58
63
this . supportsBinary = hasXHR2 && ! forceBase64 ;
64
+
65
+ if ( this . opts . withCredentials ) {
66
+ this . cookieJar = createCookieJar ( ) ;
67
+ }
59
68
}
60
69
61
70
override get name ( ) {
@@ -251,7 +260,11 @@ export class Polling extends Transport {
251
260
* @private
252
261
*/
253
262
request ( opts = { } ) {
254
- Object . assign ( opts , { xd : this . xd , xs : this . xs } , this . opts ) ;
263
+ Object . assign (
264
+ opts ,
265
+ { xd : this . xd , xs : this . xs , cookieJar : this . cookieJar } ,
266
+ this . opts
267
+ ) ;
255
268
return new Request ( this . uri ( ) , opts ) ;
256
269
}
257
270
@@ -296,7 +309,7 @@ interface RequestReservedEvents {
296
309
}
297
310
298
311
export class Request extends Emitter < { } , { } , RequestReservedEvents > {
299
- private readonly opts : { xd ; xs } & SocketOptions ;
312
+ private readonly opts : { xd ; xs ; cookieJar : CookieJar } & SocketOptions ;
300
313
private readonly method : string ;
301
314
private readonly uri : string ;
302
315
private readonly async : boolean ;
@@ -375,6 +388,8 @@ export class Request extends Emitter<{}, {}, RequestReservedEvents> {
375
388
xhr . setRequestHeader ( "Accept" , "*/*" ) ;
376
389
} catch ( e ) { }
377
390
391
+ this . opts . cookieJar ?. addCookies ( xhr ) ;
392
+
378
393
// ie6 check
379
394
if ( "withCredentials" in xhr ) {
380
395
xhr . withCredentials = this . opts . withCredentials ;
@@ -385,6 +400,10 @@ export class Request extends Emitter<{}, {}, RequestReservedEvents> {
385
400
}
386
401
387
402
xhr . onreadystatechange = ( ) => {
403
+ if ( xhr . readyState === 3 ) {
404
+ this . opts . cookieJar ?. parseCookies ( xhr ) ;
405
+ }
406
+
388
407
if ( 4 !== xhr . readyState ) return ;
389
408
if ( 200 === xhr . status || 1223 === xhr . status ) {
390
409
this . onLoad ( ) ;
0 commit comments