Skip to content

Commit e41fc34

Browse files
committed
[dotnet] Fix CDP error getting body of redirect responses
1 parent 21163d6 commit e41fc34

File tree

4 files changed

+44
-28
lines changed

4 files changed

+44
-28
lines changed

dotnet/src/webdriver/DevTools/v85/V85Network.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,18 @@ await fetch.ContinueWithAuth(new ContinueWithAuthCommandSettings()
241241
/// <returns>A task that represents the asynchronous operation.</returns>
242242
public override async Task AddResponseBody(HttpResponseData responseData)
243243
{
244-
var bodyResponse = await fetch.GetResponseBody(new Fetch.GetResponseBodyCommandSettings() { RequestId = responseData.RequestId });
245-
if (bodyResponse.Base64Encoded)
244+
// If the response is a redirect, retrieving the body will throw an error in CDP.
245+
if (responseData.StatusCode < 300 || responseData.StatusCode > 399)
246246
{
247-
responseData.Body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyResponse.Body));
248-
}
249-
else
250-
{
251-
responseData.Body = bodyResponse.Body;
247+
var bodyResponse = await fetch.GetResponseBody(new Fetch.GetResponseBodyCommandSettings() { RequestId = responseData.RequestId });
248+
if (bodyResponse.Base64Encoded)
249+
{
250+
responseData.Body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyResponse.Body));
251+
}
252+
else
253+
{
254+
responseData.Body = bodyResponse.Body;
255+
}
252256
}
253257
}
254258

dotnet/src/webdriver/DevTools/v93/V93Network.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,18 @@ await fetch.ContinueWithAuth(new ContinueWithAuthCommandSettings()
241241
/// <returns>A task that represents the asynchronous operation.</returns>
242242
public override async Task AddResponseBody(HttpResponseData responseData)
243243
{
244-
var bodyResponse = await fetch.GetResponseBody(new Fetch.GetResponseBodyCommandSettings() { RequestId = responseData.RequestId });
245-
if (bodyResponse.Base64Encoded)
244+
// If the response is a redirect, retrieving the body will throw an error in CDP.
245+
if (responseData.StatusCode < 300 || responseData.StatusCode > 399)
246246
{
247-
responseData.Body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyResponse.Body));
248-
}
249-
else
250-
{
251-
responseData.Body = bodyResponse.Body;
247+
var bodyResponse = await fetch.GetResponseBody(new Fetch.GetResponseBodyCommandSettings() { RequestId = responseData.RequestId });
248+
if (bodyResponse.Base64Encoded)
249+
{
250+
responseData.Body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyResponse.Body));
251+
}
252+
else
253+
{
254+
responseData.Body = bodyResponse.Body;
255+
}
252256
}
253257
}
254258

dotnet/src/webdriver/DevTools/v94/V94Network.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,18 @@ await fetch.ContinueWithAuth(new ContinueWithAuthCommandSettings()
241241
/// <returns>A task that represents the asynchronous operation.</returns>
242242
public override async Task AddResponseBody(HttpResponseData responseData)
243243
{
244-
var bodyResponse = await fetch.GetResponseBody(new Fetch.GetResponseBodyCommandSettings() { RequestId = responseData.RequestId });
245-
if (bodyResponse.Base64Encoded)
244+
// If the response is a redirect, retrieving the body will throw an error in CDP.
245+
if (responseData.StatusCode < 300 || responseData.StatusCode > 399)
246246
{
247-
responseData.Body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyResponse.Body));
248-
}
249-
else
250-
{
251-
responseData.Body = bodyResponse.Body;
247+
var bodyResponse = await fetch.GetResponseBody(new Fetch.GetResponseBodyCommandSettings() { RequestId = responseData.RequestId });
248+
if (bodyResponse.Base64Encoded)
249+
{
250+
responseData.Body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyResponse.Body));
251+
}
252+
else
253+
{
254+
responseData.Body = bodyResponse.Body;
255+
}
252256
}
253257
}
254258

dotnet/src/webdriver/DevTools/v95/V95Network.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,18 @@ await fetch.ContinueWithAuth(new ContinueWithAuthCommandSettings()
241241
/// <returns>A task that represents the asynchronous operation.</returns>
242242
public override async Task AddResponseBody(HttpResponseData responseData)
243243
{
244-
var bodyResponse = await fetch.GetResponseBody(new Fetch.GetResponseBodyCommandSettings() { RequestId = responseData.RequestId });
245-
if (bodyResponse.Base64Encoded)
244+
// If the response is a redirect, retrieving the body will throw an error in CDP.
245+
if (responseData.StatusCode < 300 || responseData.StatusCode > 399)
246246
{
247-
responseData.Body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyResponse.Body));
248-
}
249-
else
250-
{
251-
responseData.Body = bodyResponse.Body;
247+
var bodyResponse = await fetch.GetResponseBody(new Fetch.GetResponseBodyCommandSettings() { RequestId = responseData.RequestId });
248+
if (bodyResponse.Base64Encoded)
249+
{
250+
responseData.Body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyResponse.Body));
251+
}
252+
else
253+
{
254+
responseData.Body = bodyResponse.Body;
255+
}
252256
}
253257
}
254258

0 commit comments

Comments
 (0)