Skip to content

Commit 79658c4

Browse files
Fixes bug in Paging guidance plugin (#195)
1 parent 6530ddc commit 79658c4

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

msgraph-developer-proxy-plugins/Guidance/ODataPagingGuidancePlugin.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public override void Register(IPluginEvents pluginEvents,
2323

2424
pluginEvents.BeforeRequest += OnBeforeRequest;
2525
pluginEvents.BeforeResponse += OnBeforeResponse;
26-
pluginEvents.AfterResponse += OnAfterResponse;
2726
}
2827

2928
private void OnBeforeRequest(object? sender, ProxyRequestArgs e)
@@ -43,34 +42,21 @@ private void OnBeforeRequest(object? sender, ProxyRequestArgs e)
4342
}
4443

4544
private async void OnBeforeResponse(object? sender, ProxyResponseArgs e)
46-
{
47-
if (_urlsToWatch is null ||
48-
e.Session.HttpClient.Request.Method != "GET" ||
49-
!e.HasRequestUrlMatch(_urlsToWatch) ||
50-
e.Session.HttpClient.Response.ContentType is null ||
51-
(!e.Session.HttpClient.Response.ContentType.Contains("json") &&
52-
!e.Session.HttpClient.Response.ContentType.Contains("application/atom+xml")))
53-
{
54-
return;
55-
}
56-
57-
// necessary for the response body to be available in the AfterResponse event
58-
await e.Session.GetResponseBodyAsString();
59-
}
60-
61-
private async void OnAfterResponse(object? sender, ProxyResponseArgs e)
6245
{
6346
if (_urlsToWatch is null ||
6447
!e.HasRequestUrlMatch(_urlsToWatch) ||
6548
e.Session.HttpClient.Request.Method != "GET" ||
6649
e.Session.HttpClient.Response.StatusCode >= 300 ||
6750
e.Session.HttpClient.Response.ContentType is null ||
6851
(!e.Session.HttpClient.Response.ContentType.Contains("json") &&
69-
!e.Session.HttpClient.Response.ContentType.Contains("application/atom+xml")))
52+
!e.Session.HttpClient.Response.ContentType.Contains("application/atom+xml")) ||
53+
!e.Session.HttpClient.Response.HasBody)
7054
{
7155
return;
7256
}
7357

58+
e.Session.HttpClient.Response.KeepBody = true;
59+
7460
var nextLink = string.Empty;
7561
var bodyString = await e.Session.GetResponseBodyAsString();
7662
if (string.IsNullOrEmpty(bodyString))

0 commit comments

Comments
 (0)