Invalid HTTP header field values

On Flutter channel beta and dev, requests to certain APIs are failing because of invalid http response header field values:

E/flutter (17842): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: HttpException: Invalid HTTP header field value: "246.792µs"
E/flutter (17842): #0      _HttpHeaders._validateValue  (dart:_http/http_headers.dart:626:9)
E/flutter (17842): #1      _HttpHeaders._addAll  (dart:_http/http_headers.dart:75:18)
E/flutter (17842): #2      _HttpHeaders.add  (dart:_http/http_headers.dart:66:5)
E/flutter (17842): #3      _HttpParser._doParse  (dart:_http/http_parser.dart:719:24)
E/flutter (17842): #4      _HttpParser._parse  (dart:_http/http_parser.dart:328:7)
E/flutter (17842): #5      _HttpParser._onData  (dart:_http/http_parser.dart:850:5)

This is not the case on channel stable. Every http library I know of is affected by this (dart http, dio, etc.) when you’re not on the stable channel. I also tested it with some native libraries like Retrofit on Android which are not having those issues.

Author: Fantashit

2 thoughts on “Invalid HTTP header field values

  1. Here’s what happened:

    Dart used to parse HTTP header values as Latin-1 (by virtue of passing the individual bytes as input to String.fromCharCodes). 6a5b87f began validating HTTP header names and values are composed of allowed characters in all code paths, including the HTTP parser. It wasn’t caught that this change made the HTTP parser reject bytes 128 through 255, instead of parsing them as Latin-1 codepoints.

    (To correct misleading information above, Dart does not decode headers as UTF-8. In fact, the problem is that the the server is sending the µ as UTF-8 which Dart used to decode as µ in Latin-1.)

    This is technically a breaking change and wasn’t intended/approved as such.

    We should revert the breaking part of the change and cherry-pick it into the beta/stable channel.

    I’ll land Zichang’s commit and update the cherry-pick request.

Comments are closed.