# WebView2HeadersCollection class
{: .no_toc }

An enumerator that yields [**WebView2Header**](/tB/Packages/WebView2/WebView2Header.md) values one by one. Returned by **WebView2RequestHeaders.GetHeaders**, **WebView2ResponseHeaders.GetHeaders**, and by `For Each` over a [**WebView2RequestHeaders**](/tB/Packages/WebView2/WebView2RequestHeaders.md) or [**WebView2ResponseHeaders**](/tB/Packages/WebView2/WebView2ResponseHeaders.md) instance.

The collection implements the COM enumerator operations **Next**, **Skip**, **Reset** and **Clone**, which `For Each` and other COM enumerator clients call. They are not members that BASIC code can call. A loop reads the headers once, front to back; **Reset** starts the enumeration again from the first header. Every call to **GetHeaders** and every `For Each` loop produces a new enumerator, so a new loop always starts at the first header.

**Clone** returns an enumerator at the position of the enumerator it copies, after a **Reset** too.

A **WebView2HeadersCollection** is never created by application code. The package returns one of the four derived classes listed under [Derived classes](#derived-classes), typed as **WebView2HeadersCollection**.

```tb check_build
Private Sub WebView21_NavigationStarting( _
        ByVal Uri As String, _
        ByVal IsUserInitiated As Boolean, _
        ByVal IsRedirected As Boolean, _
        ByVal RequestHeaders As WebView2RequestHeaders, _
        Cancel As Boolean)

    Dim h As WebView2Header
    For Each h In RequestHeaders
        Debug.Print h.Name & ": " & h.Value
    Next
End Sub
```

## Derived classes

Four public classes inherit from **WebView2HeadersCollection**. Each is `[COMCreatable(False)]`, and application code does not create them: the package creates them and returns them as **WebView2HeadersCollection**. Each overrides **Reset** and **Clone** to work on its own source of headers.

| Class | Returned by | Yields |
|-------|-------------|--------|
| **WebView2HeadersCollection_RequestGetHeaders** | [**WebView2RequestHeaders.GetHeaders**](/tB/Packages/WebView2/WebView2RequestHeaders.md#getheaders) | the request headers whose name matches the *name* argument |
| **WebView2HeadersCollection_RequestEnumerator** | `For Each` over a [**WebView2RequestHeaders**](/tB/Packages/WebView2/WebView2RequestHeaders.md) | every request header |
| **WebView2HeadersCollection_ResponseGetHeaders** | [**WebView2ResponseHeaders.GetHeaders**](/tB/Packages/WebView2/WebView2ResponseHeaders.md#getheaders) | the response headers whose name matches the *name* argument |
| **WebView2HeadersCollection_ResponseEnumerator** | `For Each` over a [**WebView2ResponseHeaders**](/tB/Packages/WebView2/WebView2ResponseHeaders.md) | every response header |

## Methods

### New
{: .no_toc }

Constructs the collection from the runtime's header iterator. The constructor is **Protected**: only the four derived classes call it, and application code cannot create a **WebView2HeadersCollection**.
