# WebView2RequestHeaders class
{: .no_toc }

The mutable HTTP-request-header collection for a navigation or a web-resource request. Reached two ways:

- As the **RequestHeaders** argument of the [**NavigationStarting**](/tB/Packages/WebView2/WebView2/index.md#navigationstarting) event --- the headers about to be sent for the page navigation. Mutations made before the event handler returns are transmitted.
- Through [**WebView2Request.Headers**](/tB/Packages/WebView2/WebView2Request.md#headers) when handling a [**WebResourceRequested**](/tB/Packages/WebView2/WebView2/index.md#webresourcerequested) event.

The collection is enumerable: a `For Each` loop yields one [**WebView2Header**](/tB/Packages/WebView2/WebView2Header.md) per entry.

```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)

    If Not RequestHeaders.Contains("X-Forwarded-For") Then
        RequestHeaders.AppendHeader "X-Forwarded-For", "192.0.2.1"
    End If
End Sub
```

## Methods

### AppendHeader
{: .no_toc }

Sets the value of a header --- replacing the existing value if present, otherwise adding it. The underlying runtime call is `SetHeader`, so existing values for the named header are overwritten rather than appended; the method's name preserves twinBASIC's wrapping convention.

Syntax: *object*.**AppendHeader** *name*, *value*

*name*
: *required* A **String** header name.

*value*
: *required* A **String** header value.

### Contains
{: .no_toc }

Indicates whether a header with the given name is present in the collection.

Syntax: *object*.**Contains** ( *name* ) **As Boolean**

*name*
: *required* A **String** header name.

### GetHeader
{: .no_toc }

Returns the value of the named header.

Syntax: *object*.**GetHeader** ( *name* ) **As String**

*name*
: *required* A **String** header name.

### GetHeaders
{: .no_toc }

Returns a [**WebView2HeadersCollection**](/tB/Packages/WebView2/WebView2HeadersCollection.md) enumerator restricted to the headers that match *name* --- useful for headers that may have multiple values. Each call returns a new enumerator that starts at the first matching header.

Syntax: *object*.**GetHeaders** ( *name* ) **As WebView2HeadersCollection**

*name*
: *required* A **String** header name.

### RemoveHeader
{: .no_toc }

Removes the named header from the collection.

Syntax: *object*.**RemoveHeader** *name*

*name*
: *required* A **String** header name.

## Iteration

A `For Each` loop over the collection produces every header in turn:

```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
```

Each `For Each` loop starts at the first header. See [**WebView2HeadersCollection**](/tB/Packages/WebView2/WebView2HeadersCollection.md) for the iteration object.
