Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
7 changes: 7 additions & 0 deletions dotnet/src/webdriver/BiDi/Network/NetworkModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ public async Task<EmptyResult> SetCacheBehaviorAsync(CacheBehavior behavior, Set
return await Broker.ExecuteCommandAsync<SetCacheBehaviorCommand, EmptyResult>(new SetCacheBehaviorCommand(@params), options).ConfigureAwait(false);
}

public async Task<EmptyResult> SetExtraHeadersAsync(IEnumerable<Header> headers, SetExtraHeadersOptions? options = null)
{
var @params = new SetExtraHeadersParameters(headers, options?.Contexts, options?.UserContexts);

return await Broker.ExecuteCommandAsync<SetExtraHeadersCommand, EmptyResult>(new SetExtraHeadersCommand(@params), options).ConfigureAwait(false);
}

public async Task<EmptyResult> ContinueRequestAsync(Request request, ContinueRequestOptions? options = null)
{
var @params = new ContinueRequestParameters(request, options?.Body, options?.Cookies, options?.Headers, options?.Method, options?.Url);
Expand Down
35 changes: 35 additions & 0 deletions dotnet/src/webdriver/BiDi/Network/SetExtraHeadersCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// <copyright file="SetExtraHeadersCommand.cs" company="Selenium Committers">
// 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.
// </copyright>

using System.Collections.Generic;
using OpenQA.Selenium.BiDi.Communication;

namespace OpenQA.Selenium.BiDi.Network;

internal sealed class SetExtraHeadersCommand(SetExtraHeadersParameters @params)
: Command<SetExtraHeadersParameters, EmptyResult>(@params, "network.setExtraHeaders");

internal sealed record SetExtraHeadersParameters(IEnumerable<Header> Headers, IEnumerable<BrowsingContext.BrowsingContext>? Contexts, IEnumerable<Browser.UserContext>? UserContexts) : Parameters;

public sealed class SetExtraHeadersOptions : CommandOptions
{
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }

public IEnumerable<Browser.UserContext>? UserContexts { get; set; }
}
11 changes: 11 additions & 0 deletions dotnet/test/common/BiDi/Network/NetworkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}