HttpRequest::getRequestHeaders only seems to return a subset of headers?

Issue

As you can see, i did a request which was successful. The issue I have is the 3 lined i have printed out below.

var headerList = request.getAllResponseHeaders();
print("RunTime type of Header List: ${headerList.runtimeType}");
print("Header List Count: ${headerList.length}");
print("Header List is as follows: \n$headerList");

So it seems that request, a HttpRequest is not returning enough information. I was hoping it woudl return either a complete string of all header infomration, a Map of k=>v pairs, or an array.

Seems like it only fetched the first 64 characters.

Why would it not get all of the files? Ideally, I am trying to get the “Content-Disposition” header, by way of request.getResponseHeader("Content-Disposition"); but as you can imagine, given this information, it actually will return null, since the request cant find that information.

enter image description here

Solution

I guess you need to add

Access-Control-Expose-Headers Content-Disposition

on your server.

Access-Control-Expose-Headers (optional) – The XMLHttpRequest 2 object
has a getResponseHeader() method that returns the value of a
particular response header. During a CORS request, the
getResponseHeader() method can only access simple response headers.
Simple response headers are defined as follows:

  • Cache-Control
  • Content-Language
  • Content-Type
  • Expires
  • Last-Modified
  • Pragma

If you want clients to be able to access other headers, you
have to use the Access-Control-Expose-Headers header. The value of
this header is a comma-delimited list of response headers you want to
expose to the client.

From http://www.html5rocks.com/en/tutorials/cors/

Answered By – Günter Zöchbauer

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

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