Skip to content

Reducing a request body stream of Uint8List fails in shelf 1.1.1 or later #188

Closed
@fertrig

Description

@fertrig

The test below passes in shelf 1.0.0, but fails in shelf 1.1.1 (or later) with this message:

type '(List<int>, List<int>) => List<int>' is not a subtype of type '(Uint8List, Uint8List) => Uint8List' of 'combine'
import 'dart:convert';
import 'dart:typed_data';

import 'package:shelf/shelf.dart';
import 'package:test/test.dart';

void main() {
  group('shelf.Request.read', () {
    test('reduce stream of Uint8List', () async {
      var request = _request(body: genUint8List());
      var bodyBytes = await request.read().reduce((previous, element) {
        return [...previous, ...element];
      });
      expect(bodyBytes, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
    });
  });
}

Request _request({Map<String, String>? headers, body, Encoding? encoding}) {
  return Request('POST', Uri.parse('http://localhost/'),
      headers: headers, body: body, encoding: encoding);
}

Stream<Uint8List> genUint8List() async* {
  for (var i = 0; i <= 9; i++) {
    await Future.microtask(() => null);
    yield Uint8List.fromList([i]);
  }
}

My client application is sending json. The server started failing with that error message when I upgraded shelf. This test reproduces the error I am getting in production.

The same test passes when using a stream of List<int>. Here is a gist showing both scenarios.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions