From e5d09cb6820cf30a5d03a92c4c54e32ed9deb376 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 25 Apr 2016 12:57:09 -0700 Subject: [PATCH] Handle the case of a null body in response.dart We're supposed to return a null string when the HTTP response doesn't have a body. Also handle the case of not having a headers map. --- packages/flutter/lib/src/http/response.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/http/response.dart b/packages/flutter/lib/src/http/response.dart index e873408660..56d294559e 100644 --- a/packages/flutter/lib/src/http/response.dart +++ b/packages/flutter/lib/src/http/response.dart @@ -15,7 +15,7 @@ class Response { /// The result of decoding [bodyBytes] using ISO-8859-1. /// /// If [bodyBytes] is null, this will also be null. - String get body => _encodingForHeaders(headers).decode(bodyBytes); + String get body => bodyBytes == null ? null : _encodingForHeaders(headers).decode(bodyBytes); /// The raw byte stream. final Uint8List bodyBytes; @@ -80,6 +80,8 @@ String _getCharset(String contentType) { } Encoding _encodingForHeaders(Map headers) { + if (headers == null) + return LATIN1; String contentType = headers['content-type']; if (contentType == null) return LATIN1;