| 938 | } |
| 939 | |
| 940 | @CanIgnoreReturnValue |
| 941 | Builder setRawHost(String host) { |
| 942 | if (host.startsWith("[") && host.endsWith("]")) { |
| 943 | // IP-literal: Guava's isUriInetAddress() is almost enough but it doesn't check the scope. |
| 944 | int percentIndex = host.indexOf('%'); |
| 945 | if (percentIndex > 0) { |
| 946 | String scope = host.substring(percentIndex, host.length() - 1); |
| 947 | checkPercentEncodedArg(scope, "scope", unreservedChars); |
| 948 | } |
| 949 | } |
| 950 | // IP-literal validation is complicated so we delegate it to Guava. We use this particular |
| 951 | // method of InetAddresses because it doesn't try to match interfaces on the local machine. |
| 952 | // (The validity of a URI should be the same no matter which machine does the parsing.) |
| 953 | // TODO(jdcormie): IPFuture |
| 954 | if (!InetAddresses.isUriInetAddress(host)) { |
| 955 | // Must be a "registered name". |
| 956 | checkPercentEncodedArg(host, "host", regNameChars); |
| 957 | } |
| 958 | this.host = host; |
| 959 | return this; |
| 960 | } |
| 961 | |
| 962 | /** |
| 963 | * Specifies the "port" component of the new URI, e.g. "8080". |