Skip to content

Commit 948c7d3

Browse files
Adds support for excluding URLs. Closes #109 (#243)
1 parent d1b447c commit 948c7d3

18 files changed

+67
-51
lines changed

msgraph-developer-proxy-abstractions/BaseProxyPlugin.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
// Licensed under the MIT License.
33

44
using Microsoft.Extensions.Configuration;
5-
using System.Text.RegularExpressions;
65

76
namespace Microsoft.Graph.DeveloperProxy.Abstractions;
87

98
public abstract class BaseProxyPlugin: IProxyPlugin {
10-
protected ISet<Regex>? _urlsToWatch;
9+
protected ISet<UrlToWatch>? _urlsToWatch;
1110
protected ILogger? _logger;
1211

1312
public virtual string Name => throw new NotImplementedException();
1413
public virtual void Register(IPluginEvents pluginEvents,
1514
IProxyContext context,
16-
ISet<Regex> urlsToWatch,
15+
ISet<UrlToWatch> urlsToWatch,
1716
IConfigurationSection? configSection = null) {
1817
if (pluginEvents is null) {
1918
throw new ArgumentNullException(nameof(pluginEvents));

msgraph-developer-proxy-abstractions/IProxyPlugin.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
// Licensed under the MIT License.
33

44
using Microsoft.Extensions.Configuration;
5-
using System.Text.RegularExpressions;
65

76
namespace Microsoft.Graph.DeveloperProxy.Abstractions;
87

98
public interface IProxyPlugin {
109
string Name { get; }
1110
void Register(IPluginEvents pluginEvents,
1211
IProxyContext context,
13-
ISet<Regex> urlsToWatch,
12+
ISet<UrlToWatch> urlsToWatch,
1413
IConfigurationSection? configSection = null);
1514
}

msgraph-developer-proxy-abstractions/PluginEvents.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.CommandLine;
55
using System.CommandLine.Invocation;
6-
using System.Text.RegularExpressions;
76
using Titanium.Web.Proxy.EventArguments;
87

98
namespace Microsoft.Graph.DeveloperProxy.Abstractions;
@@ -18,8 +17,10 @@ internal ProxyHttpEventArgsBase(SessionEventArgs session) =>
1817

1918
public SessionEventArgs Session { get; }
2019

21-
public bool HasRequestUrlMatch(ISet<Regex> watchedUrls) =>
22-
watchedUrls.Any(r => r.IsMatch(Session.HttpClient.Request.RequestUri.AbsoluteUri));
20+
public bool HasRequestUrlMatch(ISet<UrlToWatch> watchedUrls) {
21+
var match = watchedUrls.FirstOrDefault(r => r.Url.IsMatch(Session.HttpClient.Request.RequestUri.AbsoluteUri));
22+
return match is not null && !match.Exclude;
23+
}
2324
}
2425

2526
public class ProxyRequestArgs : ProxyHttpEventArgsBase {
@@ -28,7 +29,7 @@ public ProxyRequestArgs(SessionEventArgs session, ResponseState responseState) :
2829
}
2930
public ResponseState ResponseState { get; }
3031

31-
public bool ShouldExecute(ISet<Regex> watchedUrls) =>
32+
public bool ShouldExecute(ISet<UrlToWatch> watchedUrls) =>
3233
!ResponseState.HasBeenSet
3334
&& HasRequestUrlMatch(watchedUrls);
3435
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Text.RegularExpressions;
2+
3+
namespace Microsoft.Graph.DeveloperProxy.Abstractions;
4+
5+
public class UrlToWatch {
6+
public bool Exclude { get; }
7+
public Regex Url { get; }
8+
9+
public UrlToWatch(Regex url, bool exclude = false)
10+
{
11+
Exclude = exclude;
12+
Url = url;
13+
}
14+
}

msgraph-developer-proxy-plugins/Behavior/RateLimitingPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private void UpdateProxyResponse(ProxyHttpEventArgsBase e, HttpStatusCode errorS
123123

124124
public override void Register(IPluginEvents pluginEvents,
125125
IProxyContext context,
126-
ISet<Regex> urlsToWatch,
126+
ISet<UrlToWatch> urlsToWatch,
127127
IConfigurationSection? configSection = null) {
128128
base.Register(pluginEvents, context, urlsToWatch, configSection);
129129

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using Microsoft.Extensions.Configuration;
55
using Microsoft.Graph.DeveloperProxy.Abstractions;
6-
using System.Text.RegularExpressions;
76
using Titanium.Web.Proxy.Http;
87

98
namespace Microsoft.Graph.DeveloperProxy.Plugins.Guidance;
@@ -13,7 +12,7 @@ public class GraphBetaSupportGuidancePlugin : BaseProxyPlugin {
1312

1413
public override void Register(IPluginEvents pluginEvents,
1514
IProxyContext context,
16-
ISet<Regex> urlsToWatch,
15+
ISet<UrlToWatch> urlsToWatch,
1716
IConfigurationSection? configSection = null) {
1817
base.Register(pluginEvents, context, urlsToWatch, configSection);
1918

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using Microsoft.Extensions.Configuration;
55
using Microsoft.Graph.DeveloperProxy.Abstractions;
6-
using System.Text.RegularExpressions;
76
using Titanium.Web.Proxy.Http;
87

98
namespace Microsoft.Graph.DeveloperProxy.Plugins.Guidance;
@@ -14,7 +13,7 @@ public class GraphClientRequestIdGuidancePlugin : BaseProxyPlugin
1413

1514
public override void Register(IPluginEvents pluginEvents,
1615
IProxyContext context,
17-
ISet<Regex> urlsToWatch,
16+
ISet<UrlToWatch> urlsToWatch,
1817
IConfigurationSection? configSection = null)
1918
{
2019
base.Register(pluginEvents, context, urlsToWatch, configSection);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using Microsoft.Extensions.Configuration;
55
using Microsoft.Graph.DeveloperProxy.Abstractions;
6-
using System.Text.RegularExpressions;
76
using Titanium.Web.Proxy.Http;
87

98
namespace Microsoft.Graph.DeveloperProxy.Plugins.Guidance;
@@ -13,7 +12,7 @@ public class GraphSdkGuidancePlugin : BaseProxyPlugin {
1312

1413
public override void Register(IPluginEvents pluginEvents,
1514
IProxyContext context,
16-
ISet<Regex> urlsToWatch,
15+
ISet<UrlToWatch> urlsToWatch,
1716
IConfigurationSection? configSection = null) {
1817
base.Register(pluginEvents, context, urlsToWatch, configSection);
1918

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using Microsoft.Extensions.Configuration;
55
using Microsoft.Graph.DeveloperProxy.Abstractions;
6-
using System.Text.RegularExpressions;
76
using Titanium.Web.Proxy.Http;
87

98
namespace Microsoft.Graph.DeveloperProxy.Plugins.Guidance;
@@ -13,7 +12,7 @@ public class GraphSelectGuidancePlugin : BaseProxyPlugin {
1312

1413
public override void Register(IPluginEvents pluginEvents,
1514
IProxyContext context,
16-
ISet<Regex> urlsToWatch,
15+
ISet<UrlToWatch> urlsToWatch,
1716
IConfigurationSection? configSection = null) {
1817
base.Register(pluginEvents, context, urlsToWatch, configSection);
1918

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Microsoft.Extensions.Configuration;
55
using Microsoft.Graph.DeveloperProxy.Abstractions;
66
using System.Text.Json;
7-
using System.Text.RegularExpressions;
87
using System.Xml.Linq;
98

109
namespace Microsoft.Graph.DeveloperProxy.Plugins.Guidance;
@@ -16,7 +15,7 @@ public class ODataPagingGuidancePlugin : BaseProxyPlugin
1615

1716
public override void Register(IPluginEvents pluginEvents,
1817
IProxyContext context,
19-
ISet<Regex> urlsToWatch,
18+
ISet<UrlToWatch> urlsToWatch,
2019
IConfigurationSection? configSection = null)
2120
{
2221
base.Register(pluginEvents, context, urlsToWatch, configSection);

0 commit comments

Comments
 (0)