http icon indicating copy to clipboard operation
http copied to clipboard

Inadvertent use of StreamedRequest with GET sends a 0-length chunk

Open eug48 opened this issue 4 years ago • 0 comments

I copied-and-pasted some code that was using StreamedRequest for a POST and used it to make a GET. This led to intermittent 400s from Google Cloud Run and it took me time & packet dumps to realise that my Dart code was sending pipelined GETs with 0-length chunks attached to them.

It might save someone some time if chunks were not sent for 0-length bodies, or if StreamedRequest were to assert that the method isn't a GET or a HEAD.

To reproduce

  1. Start an http server, e.g. python3 -m http.server 8000
  2. Start Wireshark to capture the loopback interface with a filter like tcp.dstport == 8000
  3. Run this program
import 'package:http/http.dart' as http;

void main(List<String> arguments) async {
  var req = http.StreamedRequest("GET", Uri.parse("http://localhost:8000"));
  req.sink.close();
  await http.Client().send(req);
}
  1. Observe that the HTTP request ends with a chunk ("0")

eug48 avatar Dec 11 '21 09:12 eug48