W3cubDocs

/Dart 2

responseHeaders property

Map<String, String> responseHeaders

Returns all response headers as a key-value map.

Multiple values for the same header key can be combined into one, separated by a comma and a space.

See: http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader()-method

Implementation

Map<String, String> get responseHeaders {
  // from Closure's goog.net.Xhrio.getResponseHeaders.
  var headers = <String, String>{};
  var headersString = this.getAllResponseHeaders();
  if (headersString == null) {
    return headers;
  }
  var headersList = headersString.split('\r\n');
  for (var header in headersList) {
    if (header.isEmpty) {
      continue;
    }

    var splitIdx = header.indexOf(': ');
    if (splitIdx == -1) {
      continue;
    }
    var key = header.substring(0, splitIdx).toLowerCase();
    var value = header.substring(splitIdx + 2);
    if (headers.containsKey(key)) {
      headers[key] = '${headers[key]}, $value';
    } else {
      headers[key] = value;
    }
  }
  return headers;
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.5.0/dart-html/HttpRequest/responseHeaders.html