diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs index 4a74468315f4c..aeac1520eb6b0 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs @@ -131,6 +131,7 @@ namespace OpenQA.Selenium.BiDi.Communication.Json; [JsonSerializable(typeof(Network.RemoveDataCollectorCommand))] [JsonSerializable(typeof(Network.RemoveInterceptCommand))] [JsonSerializable(typeof(Network.SetCacheBehaviorCommand))] +[JsonSerializable(typeof(Network.SetExtraHeadersCommand))] [JsonSerializable(typeof(Network.BeforeRequestSentEventArgs))] [JsonSerializable(typeof(Network.ResponseStartedEventArgs))] diff --git a/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs b/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs index 95e38245af4b5..74136bfc03bb0 100644 --- a/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs @@ -65,6 +65,13 @@ public async Task SetCacheBehaviorAsync(CacheBehavior behavior, Set return await Broker.ExecuteCommandAsync(new SetCacheBehaviorCommand(@params), options).ConfigureAwait(false); } + public async Task SetExtraHeadersAsync(IEnumerable
headers, SetExtraHeadersOptions? options = null) + { + var @params = new SetExtraHeadersParameters(headers, options?.Contexts, options?.UserContexts); + + return await Broker.ExecuteCommandAsync(new SetExtraHeadersCommand(@params), options).ConfigureAwait(false); + } + public async Task ContinueRequestAsync(Request request, ContinueRequestOptions? options = null) { var @params = new ContinueRequestParameters(request, options?.Body, options?.Cookies, options?.Headers, options?.Method, options?.Url); diff --git a/dotnet/src/webdriver/BiDi/Network/SetExtraHeadersCommand.cs b/dotnet/src/webdriver/BiDi/Network/SetExtraHeadersCommand.cs new file mode 100644 index 0000000000000..f0229cfb34fa4 --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Network/SetExtraHeadersCommand.cs @@ -0,0 +1,35 @@ +// +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +using System.Collections.Generic; +using OpenQA.Selenium.BiDi.Communication; + +namespace OpenQA.Selenium.BiDi.Network; + +internal sealed class SetExtraHeadersCommand(SetExtraHeadersParameters @params) + : Command(@params, "network.setExtraHeaders"); + +internal sealed record SetExtraHeadersParameters(IEnumerable
Headers, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; + +public sealed class SetExtraHeadersOptions : CommandOptions +{ + public IEnumerable? Contexts { get; set; } + + public IEnumerable? UserContexts { get; set; } +} diff --git a/dotnet/test/common/BiDi/Network/NetworkTest.cs b/dotnet/test/common/BiDi/Network/NetworkTest.cs index 8aa1c07601d1f..577e79a419515 100644 --- a/dotnet/test/common/BiDi/Network/NetworkTest.cs +++ b/dotnet/test/common/BiDi/Network/NetworkTest.cs @@ -251,4 +251,15 @@ public void CanSetCacheBehavior() Assert.That(async () => await bidi.Network.SetCacheBehaviorAsync(CacheBehavior.Default), Throws.Nothing); Assert.That(async () => await context.Network.SetCacheBehaviorAsync(CacheBehavior.Default), Throws.Nothing); } + + [Test] + [IgnoreBrowser(Selenium.Browser.Chrome, "Not supported yet?")] + [IgnoreBrowser(Selenium.Browser.Edge, "Not supported yet?")] + [IgnoreBrowser(Selenium.Browser.Firefox, "Not supported yet?")] + public async Task CanSetExtraHeaders() + { + var result = await bidi.Network.SetExtraHeadersAsync([new Header("x-test-header", "test-value")]); + + Assert.That(result, Is.Not.Null); + } }