From eec04e61d8e0957e204e5a75fe74d350d52dc886 Mon Sep 17 00:00:00 2001 From: Waldek Mastykarz Date: Tue, 5 Nov 2024 10:25:00 +0100 Subject: [PATCH] Fixes DevToolsPlugin failing on responses without a body. Closes #930 (#931) --- .../Inspection/DevToolsPlugin.cs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/dev-proxy-plugins/Inspection/DevToolsPlugin.cs b/dev-proxy-plugins/Inspection/DevToolsPlugin.cs index 94845b50..78130f16 100644 --- a/dev-proxy-plugins/Inspection/DevToolsPlugin.cs +++ b/dev-proxy-plugins/Inspection/DevToolsPlugin.cs @@ -112,7 +112,8 @@ private string GetBrowserPath(DevToolsPluginConfiguration configuration) private Process[] GetBrowserProcesses(string browserPath) { - return Process.GetProcesses().Where(p => { + return Process.GetProcesses().Where(p => + { try { return p.MainModule is not null && p.MainModule.FileName == browserPath; @@ -290,15 +291,18 @@ private async Task AfterResponseAsync(object sender, ProxyResponseArgs e) Body = string.Empty, Base64Encoded = false }; - if (IsTextResponse(e.Session.HttpClient.Response.ContentType)) - { - body.Body = e.Session.HttpClient.Response.BodyString; - body.Base64Encoded = false; - } - else + if (e.Session.HttpClient.Response.HasBody) { - body.Body = Convert.ToBase64String(e.Session.HttpClient.Response.Body); - body.Base64Encoded = true; + if (IsTextResponse(e.Session.HttpClient.Response.ContentType)) + { + body.Body = e.Session.HttpClient.Response.BodyString; + body.Base64Encoded = false; + } + else + { + body.Body = Convert.ToBase64String(e.Session.HttpClient.Response.Body); + body.Base64Encoded = true; + } } responseBody.Add(e.Session.HttpClient.Request.GetHashCode().ToString(), body);