Skip to content

Commit 6c76af1

Browse files
authored
[dotnet] [bidi] Support network SetExtraHeaders command (#16384)
1 parent 59a27f1 commit 6c76af1

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
136136
[JsonSerializable(typeof(Network.RemoveDataCollectorCommand))]
137137
[JsonSerializable(typeof(Network.RemoveInterceptCommand))]
138138
[JsonSerializable(typeof(Network.SetCacheBehaviorCommand))]
139+
[JsonSerializable(typeof(Network.SetExtraHeadersCommand))]
139140

140141
[JsonSerializable(typeof(Network.BeforeRequestSentEventArgs))]
141142
[JsonSerializable(typeof(Network.ResponseStartedEventArgs))]

dotnet/src/webdriver/BiDi/Network/NetworkModule.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ public async Task<EmptyResult> SetCacheBehaviorAsync(CacheBehavior behavior, Set
6565
return await Broker.ExecuteCommandAsync<SetCacheBehaviorCommand, EmptyResult>(new SetCacheBehaviorCommand(@params), options).ConfigureAwait(false);
6666
}
6767

68+
public async Task<EmptyResult> SetExtraHeadersAsync(IEnumerable<Header> headers, SetExtraHeadersOptions? options = null)
69+
{
70+
var @params = new SetExtraHeadersParameters(headers, options?.Contexts, options?.UserContexts);
71+
72+
return await Broker.ExecuteCommandAsync<SetExtraHeadersCommand, EmptyResult>(new SetExtraHeadersCommand(@params), options).ConfigureAwait(false);
73+
}
74+
6875
public async Task<EmptyResult> ContinueRequestAsync(Request request, ContinueRequestOptions? options = null)
6976
{
7077
var @params = new ContinueRequestParameters(request, options?.Body, options?.Cookies, options?.Headers, options?.Method, options?.Url);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// <copyright file="SetExtraHeadersCommand.cs" company="Selenium Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
// </copyright>
19+
20+
using System.Collections.Generic;
21+
using OpenQA.Selenium.BiDi.Communication;
22+
23+
namespace OpenQA.Selenium.BiDi.Network;
24+
25+
internal sealed class SetExtraHeadersCommand(SetExtraHeadersParameters @params)
26+
: Command<SetExtraHeadersParameters, EmptyResult>(@params, "network.setExtraHeaders");
27+
28+
internal sealed record SetExtraHeadersParameters(IEnumerable<Header> Headers, IEnumerable<BrowsingContext.BrowsingContext>? Contexts, IEnumerable<Browser.UserContext>? UserContexts) : Parameters;
29+
30+
public sealed class SetExtraHeadersOptions : CommandOptions
31+
{
32+
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
33+
34+
public IEnumerable<Browser.UserContext>? UserContexts { get; set; }
35+
}

dotnet/test/common/BiDi/Network/NetworkTest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,15 @@ public void CanSetCacheBehavior()
251251
Assert.That(async () => await bidi.Network.SetCacheBehaviorAsync(CacheBehavior.Default), Throws.Nothing);
252252
Assert.That(async () => await context.Network.SetCacheBehaviorAsync(CacheBehavior.Default), Throws.Nothing);
253253
}
254+
255+
[Test]
256+
[IgnoreBrowser(Selenium.Browser.Chrome, "Not supported yet?")]
257+
[IgnoreBrowser(Selenium.Browser.Edge, "Not supported yet?")]
258+
[IgnoreBrowser(Selenium.Browser.Firefox, "Not supported yet?")]
259+
public async Task CanSetExtraHeaders()
260+
{
261+
var result = await bidi.Network.SetExtraHeadersAsync([new Header("x-test-header", "test-value")]);
262+
263+
Assert.That(result, Is.Not.Null);
264+
}
254265
}

0 commit comments

Comments
 (0)