http
http copied to clipboard
Inadvertent use of StreamedRequest with GET sends a 0-length chunk
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
- Start an http server, e.g.
python3 -m http.server 8000 - Start Wireshark to capture the loopback interface with a filter like
tcp.dstport == 8000 - 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);
}
- Observe that the HTTP request ends with a chunk ("0")