http icon indicating copy to clipboard operation
http copied to clipboard

http response missing headers when using chrome

Open ranhorev opened this issue 5 years ago • 9 comments

Hi, i am developing a basic app that requires authentication, and i noticed that it works on ios but not on chrome(web). after a little debugging it seems like the Response object always contains only the 2 headers - content length and content type, and none of the other headers (set cookies etc). all the configuration seems fine. I also tried to manually add withCredentials and it didn't help. see screenshots

image

image

image

ranhorev avatar Jun 15 '21 08:06 ranhorev

I have the same issue with Chrome Web, except I'm looking for an "authorization" header entry with my "Bearer" token. Works on Android, but not on Web.

I can see the full headers while inspecting the call in Chrome, but it doesn't show up in the app.

dparfrey avatar Jun 17 '21 12:06 dparfrey

I fixed my problem! It's a CORS issue and not the http package. I tried the Dio package and got the same problem.

I initially got it working by using the --disable-web-security flag. See this discussion for details: https://stackoverflow.com/questions/65630743/how-to-solve-flutter-web-api-cors-error-only-with-dart-code

But I wasn't crazy about this solution, since I can see it becoming a bigger issue when I try to deploy the app. Since I'm using Rails for my backend, I managed to find this solution: https://glaucocustodio.github.io/2016/01/20/dont-forget-to-expose-headers-when-using-rack-cors/

Not sure if it'll help, but I added expose: ['authorization', 'Authorization'] to my cors.rb file. Back in business!

dparfrey avatar Jun 17 '21 15:06 dparfrey

Have you found the solutions? I am also facing the same problem. The "set-cookie" header is still missing even if apply @dparfrey solution.

tl-vt avatar Jun 26 '21 18:06 tl-vt

@trackilive I did not try further investigation by manipulating the cookies since the web app works well via web, ios, android... Also, I followed the Django (my web app) CORS guidelines. The only problem was with flutter web app. So I have some doubt in this solution, but either way i currently just perform the network debugging and developing using the simulators instead. it's less comfortable but it works

ranhorev avatar Jun 27 '21 07:06 ranhorev

As mentioned above this is a CORS browser policy issue and is not related to this package. A Access-Control-Expose-Headers header in the response can allow the browser to expose more of these headers.

natebosch avatar Jul 15 '21 19:07 natebosch

Hi, adding "Access-Control-Expose-Headers" from server side and enabling CORS , for me the problem is not resolved, Can you help me?

jump4 avatar Mar 23 '22 16:03 jump4

Can you help me?

You'd probably find better help in a place more oriented towards help debugging server/browser issues, like stack overflow.

natebosch avatar Mar 23 '22 16:03 natebosch

Can you help me?

You'd probably find better help in a place more oriented towards help debugging server/browser issues, like stack overflow.

Immagine

I have attached logs..have you suggestions? I have tried also adding "*, Authorization" on Access-Control-Expose-Headers having the same results.

Thanks

jump4 avatar Mar 24 '22 10:03 jump4

I have verified that the problem is about the content-type:

  • using content-type 'application/x-www-form-urlencoded; charset=UTF-8' on the request, authorization is not present into client side
  • using content-type 'application/json; charset=UTF-8' on the request, authorization is present correctly into client side

Do you have suggestions? Thanks

jump4 avatar Mar 25 '22 12:03 jump4