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 d7bd585be602c..34a92714e0b2d 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. - public SendingRemoteHttpRequestEventArgs(string method, string fullUrl, string requestBody) + /// If , 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; } /// /// 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))