Skip to content

HttpClient unhandled exception when handling redirects #60867

Open
@emersion

Description

@emersion

Given this code snippet:

import 'dart:io';
import 'dart:convert';

void main() async {
	var client = HttpClient();
	try {
		var req = await client.getUrl(Uri.parse('https://tinyurl.com/ircv3'));
		var resp = await req.close();
		final stringData = await resp.transform(utf8.decoder).join();
		print(stringData);
	} on Exception catch (err) {
		print('Failed to fetch URL: $err');
	}
}

The script crashes with the following uncaught exception, with no easy way to catch/prevent it:

Unhandled exception:
Invalid argument(s): Unsupported scheme 'ircs' in URI ircs://irc.libera.chat/
#0      _HttpClient._openUrl (dart:_http/http_impl.dart:3023:9)
#1      _HttpClient._openUrlFromRequest (dart:_http/http_impl.dart:3129:12)
#2      _HttpClientResponse.redirect (dart:_http/http_impl.dart:707:10)
#3      _HttpClientRequest._handleIncoming.<anonymous closure> (dart:_http/http_impl.dart:1590:27)
<asynchronous suspension>
#4      _HttpClientRequest._handleIncoming.<anonymous closure> (dart:_http/http_impl.dart:1608:7)
<asynchronous suspension>

I believe HttpClient should check that the redirect URI is valid and supported before trying to handle the redirection.

General info

Project info

  • sdk constraint: '^3.0.0'
  • dependencies: app_links, async, characters, connectivity_plus, dynamic_color, file_selector, firebase_core, firebase_messaging, flutter, flutter_apns_only, flutter_background, flutter_flipped_autocomplete, flutter_local_notifications, geolocator, hex, html, image_picker, linkify, mime, path, provider, scrollable_positioned_list, sentry, share_handler, share_plus, shared_preferences, shared_preferences_android, sqflite, sqflite_common_ffi, unicode_emojis, unifiedpush, url_launcher, webcrypto
  • dev_dependencies: flutter_lints
  • elided dependencies: 1

Process info

No Dart processes found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.library-iotriagedIssue has been triaged by sub team

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions