blob: 95896f2c1116e469efd2fa38396f21b5c636c29a [file] [log] [blame]
Ian Hickson449f4a62019-11-27 15:04:02 -08001// Copyright 2014 The Flutter Authors. All rights reserved.
Danny Tuppenyb16ef482019-01-10 07:47:29 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'dart:async';
6
Danny Tuppenyb16ef482019-01-10 07:47:29 +00007import 'doctor.dart';
Jonah Williamsee7a37f2020-01-06 11:04:20 -08008import 'globals.dart' as globals;
Danny Tuppenyb16ef482019-01-10 07:47:29 +00009
10class ProxyValidator extends DoctorValidator {
11 ProxyValidator() : super('Proxy Configuration');
12
13 static bool get shouldShow => _getEnv('HTTP_PROXY').isNotEmpty;
14
15 final String _httpProxy = _getEnv('HTTP_PROXY');
16 final String _noProxy = _getEnv('NO_PROXY');
17
18 /// Gets a trimmed, non-null environment variable. If the variable is not set
19 /// an empty string will be returned. Checks for the lowercase version of the
20 /// environment variable first, then uppercase to match Dart's HTTP implementation.
21 static String _getEnv(String key) =>
Jonah Williamsee7a37f2020-01-06 11:04:20 -080022 globals.platform.environment[key.toLowerCase()]?.trim() ??
23 globals.platform.environment[key.toUpperCase()]?.trim() ??
Danny Tuppenyb16ef482019-01-10 07:47:29 +000024 '';
25
26 @override
27 Future<ValidationResult> validate() async {
28 final List<ValidationMessage> messages = <ValidationMessage>[];
29
30 if (_httpProxy.isNotEmpty) {
31 messages.add(ValidationMessage('HTTP_PROXY is set'));
32
33 if (_noProxy.isEmpty) {
34 messages.add(ValidationMessage.hint('NO_PROXY is not set'));
35 } else {
36 messages.add(ValidationMessage('NO_PROXY is $_noProxy'));
Alexandre Ardhuin4f9b6cf2020-01-07 16:32:04 +010037 for (final String host in const <String>['127.0.0.1', 'localhost']) {
Danny Tuppenyb16ef482019-01-10 07:47:29 +000038 final ValidationMessage msg = _noProxy.contains(host)
39 ? ValidationMessage('NO_PROXY contains $host')
40 : ValidationMessage.hint('NO_PROXY does not contain $host');
41
42 messages.add(msg);
43 }
44 }
45 }
46
47 final bool hasIssues =
48 messages.any((ValidationMessage msg) => msg.isHint || msg.isHint);
49
50 return ValidationResult(
51 hasIssues ? ValidationType.partial : ValidationType.installed,
52 messages,
53 );
54 }
55}