# WebServerDispatcher

Artifact: [androidx.media3:media3-test-utils](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/test/utils/WebServerDispatcher.java+class:androidx.media3.test.utils.WebServerDispatcher)

*** ** * ** ***

<br />

```
@UnstableApi
public final class WebServerDispatcher
```

<br />

*** ** * ** ***

A Dispatcher for okhttp3.mockwebserver.MockWebServer that allows per-path customisation of the static data served.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/test/utils/WebServerDispatcher.Resource` A resource served by `https://developer.android.com/reference/androidx/media3/test/utils/WebServerDispatcher`. |
| `public final class https://developer.android.com/reference/androidx/media3/test/utils/WebServerDispatcher.Resource.Builder` Builder for `https://developer.android.com/reference/androidx/media3/test/utils/WebServerDispatcher.Resource`. |

| ### Constants |
|---|---|
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/test/utils/WebServerDispatcher#NOT_FOUND_BODY() = "Resource not found!"` The body associated with a response for an unrecognized path. |

| ### Public methods |
|---|---|
| `MockResponse` | `https://developer.android.com/reference/androidx/media3/test/utils/WebServerDispatcher#dispatch(RecordedRequest)(RecordedRequest request)` |
| `static https://developer.android.com/reference/androidx/media3/test/utils/WebServerDispatcher` | `https://developer.android.com/reference/androidx/media3/test/utils/WebServerDispatcher#forResources(java.lang.Iterable<androidx.media3.test.utils.WebServerDispatcher.Resource>)(https://developer.android.com/reference/java/lang/Iterable.html<https://developer.android.com/reference/androidx/media3/test/utils/WebServerDispatcher.Resource> resources)` Constructs a dispatcher that handles requests based the provided `https://developer.android.com/reference/androidx/media3/test/utils/WebServerDispatcher.Resource` instances. |
| `static https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/test/utils/WebServerDispatcher#getRequestPath(RecordedRequest)(RecordedRequest request)` Returns the path for a given RecordedRequest, stripping any query parameters. |

## Constants

### NOT_FOUND_BODY

```
public static final String NOT_FOUND_BODY = "Resource not found!"
```

The body associated with a response for an unrecognized path.

## Public methods

### dispatch

```
public MockResponse dispatch(RecordedRequest request)
```

### forResources

```
public static WebServerDispatcher forResources(Iterable<WebServerDispatcher.Resource> resources)
```

Constructs a dispatcher that handles requests based the provided `https://developer.android.com/reference/androidx/media3/test/utils/WebServerDispatcher.Resource` instances.

### getRequestPath

```
public static String getRequestPath(RecordedRequest request)
```

Returns the path for a given RecordedRequest, stripping any query parameters.