Why can't I read out the cookies from response header in flutter web but chrome can?

Viewed 588

I'm trying to read out the cookies from a response in flutter web app. Unfortunately I can't read it out although the browser can (Brave, chromium).
I'm doing a post request using dio. As interceptor for getting all cookies from a response automatically, i've added dio cookie manager to it:

var dio = Dio();
var cookieJar = CookieJar();
dio.interceptors.add(CookieManager(cookieJar));

I also added the LogInterceptor class to it.

Here's the problem: In the browser I can see that a cookie is set in response header using chrome Dev Tools > Network and examining the request:

Request:
  Request URL: https://123.123.123.123/api/login/password
  Request Method: POST
  Status Code: 200 OK
  Remote Address: 123.123.123.123:443
  Referrer Policy: strict-origin-when-cross-origin

Response:
  Access-Control-Expose-Headers: Set-Cookie
  Content-Length: 24
  Content-Type: application/json
  Date: Fri, 18 Jun 2021 13:55:05 GMT
  Server: MyServer
  Set-Cookie: my-cookie-session=123456789; Expires="Fri Jun 18 14:55:05 2021"; SameSite=Strict

The LogInterceptor prints this into the console:

*** Response ***
uri: https://123.123.123.123/api/login/password
statusCode: 200
headers:
access-control-expose-headers: Set-Cookie
content-length: 24
content-type: application/json
date: Fri 18 Jun 2021 13:55:05 GMT
server: MyServer

When printing out how much and which cookies are in the jar after that, the result is 0 and an empty list:

cookieJar.loadForRequest(_getUrl("/api/login/password")).then((value) {
  print("CookieCount: " + value.length.toString());
  value.forEach((element) {
    print(element.name + " " + element.value.toString());
  });
});
CookieCount: 0

Does someone know why the browser can read out the cookie but the flutter web app can't? Furthermore the cookie is not set in browser, I can only display it when examining the network requests as stated above.

0 Answers
Related