Skip to content

Commit

Permalink
[dotnet] Fix CDP error getting body of redirect responses
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Oct 13, 2021
1 parent 21163d6 commit e41fc34
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 28 deletions.
18 changes: 11 additions & 7 deletions dotnet/src/webdriver/DevTools/v85/V85Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,18 @@ await fetch.ContinueWithAuth(new ContinueWithAuthCommandSettings()
/// <returns>A task that represents the asynchronous operation.</returns>
public override async Task AddResponseBody(HttpResponseData responseData)
{
var bodyResponse = await fetch.GetResponseBody(new Fetch.GetResponseBodyCommandSettings() { RequestId = responseData.RequestId });
if (bodyResponse.Base64Encoded)
// If the response is a redirect, retrieving the body will throw an error in CDP.
if (responseData.StatusCode < 300 || responseData.StatusCode > 399)
{
responseData.Body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyResponse.Body));
}
else
{
responseData.Body = bodyResponse.Body;
var bodyResponse = await fetch.GetResponseBody(new Fetch.GetResponseBodyCommandSettings() { RequestId = responseData.RequestId });
if (bodyResponse.Base64Encoded)
{
responseData.Body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyResponse.Body));
}
else
{
responseData.Body = bodyResponse.Body;
}
}
}

Expand Down
18 changes: 11 additions & 7 deletions dotnet/src/webdriver/DevTools/v93/V93Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,18 @@ await fetch.ContinueWithAuth(new ContinueWithAuthCommandSettings()
/// <returns>A task that represents the asynchronous operation.</returns>
public override async Task AddResponseBody(HttpResponseData responseData)
{
var bodyResponse = await fetch.GetResponseBody(new Fetch.GetResponseBodyCommandSettings() { RequestId = responseData.RequestId });
if (bodyResponse.Base64Encoded)
// If the response is a redirect, retrieving the body will throw an error in CDP.
if (responseData.StatusCode < 300 || responseData.StatusCode > 399)
{
responseData.Body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyResponse.Body));
}
else
{
responseData.Body = bodyResponse.Body;
var bodyResponse = await fetch.GetResponseBody(new Fetch.GetResponseBodyCommandSettings() { RequestId = responseData.RequestId });
if (bodyResponse.Base64Encoded)
{
responseData.Body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyResponse.Body));
}
else
{
responseData.Body = bodyResponse.Body;
}
}
}

Expand Down
18 changes: 11 additions & 7 deletions dotnet/src/webdriver/DevTools/v94/V94Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,18 @@ await fetch.ContinueWithAuth(new ContinueWithAuthCommandSettings()
/// <returns>A task that represents the asynchronous operation.</returns>
public override async Task AddResponseBody(HttpResponseData responseData)
{
var bodyResponse = await fetch.GetResponseBody(new Fetch.GetResponseBodyCommandSettings() { RequestId = responseData.RequestId });
if (bodyResponse.Base64Encoded)
// If the response is a redirect, retrieving the body will throw an error in CDP.
if (responseData.StatusCode < 300 || responseData.StatusCode > 399)
{
responseData.Body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyResponse.Body));
}
else
{
responseData.Body = bodyResponse.Body;
var bodyResponse = await fetch.GetResponseBody(new Fetch.GetResponseBodyCommandSettings() { RequestId = responseData.RequestId });
if (bodyResponse.Base64Encoded)
{
responseData.Body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyResponse.Body));
}
else
{
responseData.Body = bodyResponse.Body;
}
}
}

Expand Down
18 changes: 11 additions & 7 deletions dotnet/src/webdriver/DevTools/v95/V95Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,18 @@ await fetch.ContinueWithAuth(new ContinueWithAuthCommandSettings()
/// <returns>A task that represents the asynchronous operation.</returns>
public override async Task AddResponseBody(HttpResponseData responseData)
{
var bodyResponse = await fetch.GetResponseBody(new Fetch.GetResponseBodyCommandSettings() { RequestId = responseData.RequestId });
if (bodyResponse.Base64Encoded)
// If the response is a redirect, retrieving the body will throw an error in CDP.
if (responseData.StatusCode < 300 || responseData.StatusCode > 399)
{
responseData.Body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyResponse.Body));
}
else
{
responseData.Body = bodyResponse.Body;
var bodyResponse = await fetch.GetResponseBody(new Fetch.GetResponseBodyCommandSettings() { RequestId = responseData.RequestId });
if (bodyResponse.Base64Encoded)
{
responseData.Body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyResponse.Body));
}
else
{
responseData.Body = bodyResponse.Body;
}
}
}

Expand Down

0 comments on commit e41fc34

Please sign in to comment.