rhttp
rhttp copied to clipboard
Empty request line when using RhttpCompatibleClient with Dio and custom 'host' header
When using RhttpCompatibleClient with Dio and add custom request header with host then the request line will empty.
Steps to reproduce:
import 'package:dio/dio.dart';
import 'package:dio_compatibility_layer/dio_compatibility_layer.dart';
import 'package:flutter/material.dart';
import 'package:rhttp/rhttp.dart';
Future<void> main() async {
await Rhttp.init();
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Dio? _client;
Response? response;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Test Page'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: () async {
_client ??= await _createDioClient();
try {
final res = await _client!.getUri(
Uri.https('tienisto.com'),
);
setState(() {
response = res;
});
} on DioException catch (e) {
print(e.response);
}
},
child: const Text('Test'),
),
if (response != null) Text(response!.statusCode.toString()),
if (response != null)
Card(
child: Text(response!.data.substring(0, 100).toString()),
),
if (response != null)
Card(
child: Text(response!.headers.toString()),
),
],
),
),
),
);
}
}
Future<Dio> _createDioClient() async {
final dio = Dio();
final compatibleClient = await RhttpCompatibleClient.create();
dio.httpClientAdapter = ConversionLayerAdapter(compatibleClient);
// using custom host header
dio.options.headers.addAll({'host': 'tienisto.com'});
return dio;
}
Console Output:
flutter: DioException Response: <html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx</center>
</body>
</html>
I try to change the httpVersionPref to HttpVersionPref.http1_0 and HttpVersionPref.http1_1 it works.
But change the setting to http2 or http3 than not working.
final compatibleClient = await RhttpCompatibleClient.create(
settings: const ClientSettings(
// not working with http2 or http3
httpVersionPref: HttpVersionPref.http2,
),
);