From 6eb1d894b47f4af2c0178e386a304549ce665284 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Fri, 24 Jan 2025 13:28:57 -0500 Subject: [PATCH 1/2] [dotnet] Annotate nullability on `SendingRemoteHttpRequestEventArgs` --- .../SendingRemoteHttpRequestEventArgs.cs | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/dotnet/src/webdriver/Remote/SendingRemoteHttpRequestEventArgs.cs b/dotnet/src/webdriver/Remote/SendingRemoteHttpRequestEventArgs.cs index d7bd585be602c..17159d2b3e685 100644 --- a/dotnet/src/webdriver/Remote/SendingRemoteHttpRequestEventArgs.cs +++ b/dotnet/src/webdriver/Remote/SendingRemoteHttpRequestEventArgs.cs @@ -20,6 +20,8 @@ using System; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.Remote { /// @@ -27,10 +29,7 @@ namespace OpenQA.Selenium.Remote /// public class SendingRemoteHttpRequestEventArgs : EventArgs { - private string method; - private string fullUrl; - private string requestBody; - private Dictionary headers = new Dictionary(); + private readonly Dictionary headers = new Dictionary(); /// /// Initializes a new instance of the class. @@ -38,45 +37,34 @@ public class SendingRemoteHttpRequestEventArgs : EventArgs /// The HTTP method of the request being sent. /// The full URL of the request being sent. /// The body of the request. + /// If , , or are null. public SendingRemoteHttpRequestEventArgs(string method, string fullUrl, string requestBody) { - this.method = method; - this.fullUrl = fullUrl; - this.requestBody = requestBody; + this.Method = method ?? throw new ArgumentNullException(nameof(method)); + this.FullUrl = fullUrl ?? throw new ArgumentNullException(nameof(fullUrl)); + this.RequestBody = requestBody ?? throw new ArgumentNullException(nameof(requestBody)); } /// /// Gets the HTTP method for the HTTP request. /// - public string Method - { - get { return this.method; } - } + public string Method { get; } /// /// Gets the full URL of the HTTP request. /// - public string FullUrl - { - get { return this.fullUrl; } - } + public string FullUrl { get; } /// /// Gets the body of the HTTP request as a string. /// - public string RequestBody - { - get { return this.requestBody; } - } + public string RequestBody { get; } /// /// Gets a read-only dictionary of the headers of the HTTP request. /// Does not include default headers of the web client making the request. /// - public IReadOnlyDictionary Headers - { - get { return this.headers; } - } + public IReadOnlyDictionary Headers => this.headers; /// /// Adds a header to the HTTP request. @@ -88,6 +76,8 @@ public IReadOnlyDictionary Headers /// HTTP request being sent; however, be aware they may be overwritten by /// the client raising the event. /// + /// If is or . + /// If is . public void AddHeader(string headerName, string headerValue) { if (string.IsNullOrEmpty(headerName)) From b83facd4785701ffd91fe05231b8f695beb39c87 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Fri, 24 Jan 2025 15:00:30 -0500 Subject: [PATCH 2/2] Do not consume our public-facing HTTP request event args body --- dotnet/src/webdriver/Remote/HttpCommandExecutor.cs | 2 +- .../webdriver/Remote/SendingRemoteHttpRequestEventArgs.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs b/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs index 5bb3274e4b020..9ab474b8ec235 100644 --- a/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs +++ b/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs @@ -280,7 +280,7 @@ private async Task MakeHttpRequest(HttpRequestInfo requestInfo acceptHeader.CharSet = Utf8CharsetType; requestMessage.Headers.Accept.Add(acceptHeader); - byte[] bytes = Encoding.UTF8.GetBytes(eventArgs.RequestBody); + byte[] bytes = Encoding.UTF8.GetBytes(requestInfo.RequestBody); requestMessage.Content = new ByteArrayContent(bytes, 0, bytes.Length); MediaTypeHeaderValue contentTypeHeader = new MediaTypeHeaderValue(JsonMimeType); diff --git a/dotnet/src/webdriver/Remote/SendingRemoteHttpRequestEventArgs.cs b/dotnet/src/webdriver/Remote/SendingRemoteHttpRequestEventArgs.cs index 17159d2b3e685..34a92714e0b2d 100644 --- a/dotnet/src/webdriver/Remote/SendingRemoteHttpRequestEventArgs.cs +++ b/dotnet/src/webdriver/Remote/SendingRemoteHttpRequestEventArgs.cs @@ -37,12 +37,12 @@ public class SendingRemoteHttpRequestEventArgs : EventArgs /// The HTTP method of the request being sent. /// The full URL of the request being sent. /// The body of the request. - /// If , , or are null. - public SendingRemoteHttpRequestEventArgs(string method, string fullUrl, string requestBody) + /// If , are null. + public SendingRemoteHttpRequestEventArgs(string method, string fullUrl, string? requestBody) { this.Method = method ?? throw new ArgumentNullException(nameof(method)); this.FullUrl = fullUrl ?? throw new ArgumentNullException(nameof(fullUrl)); - this.RequestBody = requestBody ?? throw new ArgumentNullException(nameof(requestBody)); + this.RequestBody = requestBody; } /// @@ -58,7 +58,7 @@ public SendingRemoteHttpRequestEventArgs(string method, string fullUrl, string r /// /// Gets the body of the HTTP request as a string. /// - public string RequestBody { get; } + public string? RequestBody { get; } /// /// Gets a read-only dictionary of the headers of the HTTP request.