# ProxyConfig.Builder

Artifact: [androidx.webkit:webkit](https://developer.android.com/jetpack/androidx/releases/webkit) [View Source](https://cs.android.com/search?q=file:androidx/webkit/ProxyConfig.java+class:androidx.webkit.ProxyConfig.Builder) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)

*** ** * ** ***

<br />

```
public final class ProxyConfig.Builder
```

<br />

*** ** * ** ***

ProxyConfig builder. Use `https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder#addProxyRule(java.lang.String)` or `https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder#addProxyRule(java.lang.String,java.lang.String)` to add proxy rules. Use `https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder#addBypassRule(java.lang.String)` to add bypass rules. Use `https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder#build()` to build this into a `https://developer.android.com/reference/androidx/webkit/ProxyConfig` object.

**Note:** applying a `ProxyConfig` with no rules will cause all connections to be made directly.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder#Builder()()` Create an empty ProxyConfig Builder. |
| `https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder#Builder(androidx.webkit.ProxyConfig)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig proxyConfig)` Create a ProxyConfig Builder from an existing ProxyConfig object. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder` | `https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder#addBypassRule(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html bypassRule)` Adds a new bypass rule that describes URLs that should skip proxy override settings and make a direct connection instead. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder` | `https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder#addDirect()()` Adds a proxy rule so URLs are connected to directly instead of using a proxy server. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder` | `https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder#addDirect(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html schemeFilter)` Adds a proxy rule so URLs that match the scheme filter are connected to directly instead of using a proxy server. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder` | `https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder#addProxyRule(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html proxyUrl)` Adds a proxy to be used for all URLs. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder` | `https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder#addProxyRule(java.lang.String,java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html proxyUrl, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html schemeFilter)` This does everything that `https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder#addProxyRule(java.lang.String)` does, but only applies to URLs using `schemeFilter`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig` | `https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder#build()()` Builds the current rules into a ProxyConfig object. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder` | `https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder#bypassSimpleHostnames()()` Hostnames without a period in them (and that are not IP literals) will skip proxy settings and be connected to directly instead. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder` | `https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder#removeImplicitRules()()` By default, certain hostnames implicitly bypass the proxy if they are link-local IPs, or localhost addresses. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder` | `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(name = https://developer.android.com/reference/androidx/webkit/WebViewFeature.PROXY_OVERRIDE_REVERSE_BYPASS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder#setReverseBypassEnabled(boolean)(boolean reverseBypass)` Reverse the bypass list. |

## Public constructors

### Builder

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)

```
public Builder()
```

Create an empty ProxyConfig Builder.

### Builder

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)

```
public Builder(@NonNull ProxyConfig proxyConfig)
```

Create a ProxyConfig Builder from an existing ProxyConfig object.

## Public methods

### addBypassRule

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)

```
public @NonNull ProxyConfig.Builder addBypassRule(@NonNull String bypassRule)
```

Adds a new bypass rule that describes URLs that should skip proxy override settings and make a direct connection instead. These can be URLs or IP addresses. Wildcards are accepted. For instance, the rule `"*example.com"` would mean that requests to `"http://example.com"` and `"www.example.com"` would not be directed to any proxy, instead, would be made directly to the origin specified by the URL.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html bypassRule` | Rule to be added to the exclusion list |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder` | This Builder object |

### addDirect

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)

```
public @NonNull ProxyConfig.Builder addDirect()
```

Adds a proxy rule so URLs are connected to directly instead of using a proxy server.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder` | This Builder object |

### addDirect

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)

```
public @NonNull ProxyConfig.Builder addDirect(@NonNull String schemeFilter)
```

Adds a proxy rule so URLs that match the scheme filter are connected to directly instead of using a proxy server.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html schemeFilter` | Scheme filter |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder` | This Builder object |

### addProxyRule

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)

```
public @NonNull ProxyConfig.Builder addProxyRule(@NonNull String proxyUrl)
```

Adds a proxy to be used for all URLs. This method can be called multiple times to add multiple rules. Additional rules have decreasing precedence.

Proxy is a string in the format `[scheme://]host[:port]`. Scheme is optional, if present must be `HTTP`, `HTTPS` or [SOCKS](https://tools.ietf.org/html/rfc1928) and defaults to `HTTP`. Host is one of an IPv6 literal with brackets, an IPv4 literal or one or more labels separated by a period. Port number is optional and defaults to `80` for `HTTP`, `443` for `HTTPS` and `1080` for `SOCKS`.

The correct syntax for hosts is defined by [RFC 3986](https://tools.ietf.org/html/rfc3986#section-3.2.2)

Examples:

| Scheme | Host | Port | Proxy URL |
|---|---|---|---|
|   | example.com |   | example.com |
| https | example.com |   | https://example.com |
|   | example.com | 1111 | example.com:1111 |
| https | example.com | 1111 | https://example.com:1111 |
|   | 192.168.1.1 |   | 192.168.1.1 |
|   | 192.168.1.1 | 2020 | 192.168.1.1:2020 |
|   | \[10:20:30:40:50:60:70:80\] |   | \[10:20:30:40:50:60:70:80\] |

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html proxyUrl` | Proxy URL |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder` | This Builder object |

### addProxyRule

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)

```
public @NonNull ProxyConfig.Builder addProxyRule(@NonNull String proxyUrl, @NonNull String schemeFilter)
```

This does everything that `https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder#addProxyRule(java.lang.String)` does, but only applies to URLs using `schemeFilter`. Scheme filter must be one of `https://developer.android.com/reference/androidx/webkit/ProxyConfig#MATCH_HTTP()`, `https://developer.android.com/reference/androidx/webkit/ProxyConfig#MATCH_HTTPS()` or `https://developer.android.com/reference/androidx/webkit/ProxyConfig#MATCH_ALL_SCHEMES()`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html proxyUrl` | Proxy URL |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html schemeFilter` | Scheme filter |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder` | This Builder object |

### build

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)

```
public @NonNull ProxyConfig build()
```

Builds the current rules into a ProxyConfig object.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig` | The ProxyConfig object represented by this Builder |

### bypassSimpleHostnames

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)

```
public @NonNull ProxyConfig.Builder bypassSimpleHostnames()
```

Hostnames without a period in them (and that are not IP literals) will skip proxy settings and be connected to directly instead. Examples: `"abc"`, `"local"`, `"some-domain"`.

Hostnames with a trailing dot are not considered simple by this definition.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder` | This Builder object |

### removeImplicitRules

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)

```
public @NonNull ProxyConfig.Builder removeImplicitRules()
```

By default, certain hostnames implicitly bypass the proxy if they are link-local IPs, or localhost addresses. For instance hostnames matching any of (non-exhaustive list):

- localhost
- \*.localhost
- \[::1\]
- 127.0.0.1/8
- 169.254/16
- \[FE80::\]/10

Call this function to override the default behavior and force localhost and link-local URLs to be sent through the proxy.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder` | This Builder object |

### setReverseBypassEnabled

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.5.0)

```
@RequiresFeature(name = WebViewFeature.PROXY_OVERRIDE_REVERSE_BYPASS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public @NonNull ProxyConfig.Builder setReverseBypassEnabled(boolean reverseBypass)
```

Reverse the bypass list.

The default value is `false`, in which case all URLs will use proxy settings except the ones in the bypass list, which will be connected to directly instead.

If set to `true`, then only URLs in the bypass list will use these proxy settings, and all other URLs will be connected to directly.

Use `https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder#addBypassRule(java.lang.String)` to add bypass rules.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig.Builder` | This Builder object |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | if the `https://developer.android.com/reference/androidx/webkit/WebViewFeature#PROXY_OVERRIDE_REVERSE_BYPASS()` feature is not supported. This should be checked before use with `https://developer.android.com/reference/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String)`. |