Response headers in Dart BrowserClient


I have a code where I POST a request and the response code is 201 created with “Location”: “URL” header of the new created resource.

final Response response = await, body: plan);
return _getPlan(response.headers['location']);

Where _http is a BrowserClient from the package http-0.12.0+1. But the response.headers['Location'] is empty. The headers array itself contains only one element Content-Type.
In Chrome developers tools I see all response headers including Location.
What am I doing wrong? How can I access the response headers?


Thanks to Günter Zöchbauer for pointing me for the answer. As described at the missing header is Access-Control-Expose-Headers (not Access-Control-Allow-Headers).

As I use Dart Aqueduct on the server side I had to add this line to the Channel prepare() method

class MyAppChannel extends ApplicationChannel {
  Future prepare() async {
    // ... some code

so the responses now contain Access-Control-Expose-Headers: location

Answered By – Martin Edlman

Answer Checked By – Katrina (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *