Skip to content

Commit

Permalink
[dotnet] Fix HttpCommandExecutor events
Browse files Browse the repository at this point in the history
This is mainly for the purpose of fixing the ability to get the
information of what HTTP requests are being sent to the remote end of
the WebDriver session.
  • Loading branch information
jimevans committed Aug 26, 2021
1 parent cfde816 commit 26b625a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
26 changes: 1 addition & 25 deletions dotnet/src/webdriver/Remote/HttpCommandExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ private void CreateHttpClient()
}

httpClientHandler.Proxy = this.Proxy;
// httpClientHandler.MaxConnectionsPerServer = 2000;

this.client = new HttpClient(httpClientHandler);
string userAgentString = string.Format(CultureInfo.InvariantCulture, UserAgentHeaderTemplate, ResourceUtilities.AssemblyVersion, ResourceUtilities.PlatformFamily);
Expand All @@ -249,7 +248,7 @@ private void CreateHttpClient()

private async Task<HttpResponseInfo> MakeHttpRequest(HttpRequestInfo requestInfo)
{
SendingRemoteHttpRequestEventArgs eventArgs = new SendingRemoteHttpRequestEventArgs(null, requestInfo.RequestBody);
SendingRemoteHttpRequestEventArgs eventArgs = new SendingRemoteHttpRequestEventArgs(requestInfo.HttpMethod, requestInfo.FullUri.ToString(), requestInfo.RequestBody);
this.OnSendingRemoteHttpRequest(eventArgs);

HttpMethod method = new HttpMethod(requestInfo.HttpMethod);
Expand Down Expand Up @@ -301,29 +300,6 @@ private Response CreateResponse(HttpResponseInfo responseInfo)
response.Value = body;
}

//if (this.CommandInfoRepository.SpecificationLevel < 1 && (responseInfo.StatusCode < HttpStatusCode.OK || responseInfo.StatusCode >= HttpStatusCode.BadRequest))
//{
// if (responseInfo.StatusCode >= HttpStatusCode.BadRequest && responseInfo.StatusCode < HttpStatusCode.InternalServerError)
// {
// response.Status = WebDriverResult.UnhandledError;
// }
// else if (responseInfo.StatusCode >= HttpStatusCode.InternalServerError)
// {
// if (responseInfo.StatusCode == HttpStatusCode.NotImplemented)
// {
// response.Status = WebDriverResult.UnknownCommand;
// }
// else if (response.Status == WebDriverResult.Success)
// {
// response.Status = WebDriverResult.UnhandledError;
// }
// }
// else
// {
// response.Status = WebDriverResult.UnhandledError;
// }
//}

if (response.Value is string)
{
response.Value = ((string)response.Value).Replace("\r\n", "\n").Replace("\n", Environment.NewLine);
Expand Down
30 changes: 25 additions & 5 deletions dotnet/src/webdriver/Remote/SendingRemoteHttpRequestEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,46 @@ namespace OpenQA.Selenium.Remote
/// </summary>
public class SendingRemoteHttpRequestEventArgs : EventArgs
{
private HttpWebRequest request;
private string method;
private string fullUrl;
private string requestBody;

/// <summary>
/// Initializes a new instance of the <see cref="SendingRemoteHttpRequestEventArgs"/> class.
/// </summary>
/// <param name="request">The <see cref="HttpWebRequest"/> object being sent.</param>
/// <param name="method">The HTTP method of the request being sent.</param>
/// <param name="fullUrl">The full URL of the request being sent.</param>
/// <param name="requestBody">The body of the request.</param>
public SendingRemoteHttpRequestEventArgs(HttpWebRequest request, string requestBody)
public SendingRemoteHttpRequestEventArgs(string method, string fullUrl, string requestBody)
{
this.request = request;
this.method = method;
this.fullUrl = fullUrl;
this.requestBody = requestBody;
}

/// <summary>
/// Gets the <see cref="HttpWebRequest"/> object representing the HTTP request being sent.
/// </summary>
[Obsolete("Bindings no longer use HttpWebRequest. This property will return null, and will be removed in a future release.")]
public HttpWebRequest Request
{
get { return this.request; }
get { return null; }
}

/// <summary>
/// Gets the HTTP method for the HTTP request.
/// </summary>
public string Method
{
get { return this.method; }
}

/// <summary>
/// Gets the full URL of the HTTP request.
/// </summary>
public string FullUrl
{
get { return this.fullUrl; }
}

/// <summary>
Expand Down

0 comments on commit 26b625a

Please sign in to comment.