From 59ccb11fa4d0e45a9514f38264179405b770afc2 Mon Sep 17 00:00:00 2001 From: Paul Hammant Date: Sun, 25 Sep 2022 14:36:56 +0100 Subject: [PATCH] remove custom optons logic --- .../AspNetCoreServirtiumServer.cs | 38 ++++++------------- .../Interactions/InteractionRecorder.cs | 1 + 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/Servirtium.AspNetCore/AspNetCoreServirtiumServer.cs b/Servirtium.AspNetCore/AspNetCoreServirtiumServer.cs index 28684ea..b3fcc83 100644 --- a/Servirtium.AspNetCore/AspNetCoreServirtiumServer.cs +++ b/Servirtium.AspNetCore/AspNetCoreServirtiumServer.cs @@ -74,35 +74,21 @@ internal AspNetCoreServirtiumServer(IHostBuilder hostBuilder, IServirtiumRequest _logger.LogInformation($"Received request: {ctx.Request.Method} {ctx.Request.Path}."); try { - if (HttpMethods.IsOptions(ctx.Request.Method)) - { - //Kill CORS in the face, bypass any Servirtium logic. - ctx.Response.Headers.Append("Access-Control-Allow-Origin", new StringValues("*")); - ctx.Response.Headers.Append("Access-Control-Allow-Methods", new StringValues("*")); - ctx.Response.Headers.Append("Access-Control-Allow-Headers", new StringValues("*")); - ctx.Response.Headers.Append("Access-Control-Allow-Credentials", new StringValues(new string[] { "true", ctx.Request.Host.Value })); - ctx.Response.Headers.Append("Access-Control-Max-Age", new StringValues("864000")); + var targetHost = new Uri($"{ctx.Request.Scheme}{Uri.SchemeDelimiter}{ctx.Request.Host}"); + var pathAndQuery = $"{ctx.Request.Path}{ctx.Request.QueryString}"; - } - else + ctx.Response.OnCompleted(() => { - var targetHost = new Uri($"{ctx.Request.Scheme}{Uri.SchemeDelimiter}{ctx.Request.Host}"); - var pathAndQuery = $"{ctx.Request.Path}{ctx.Request.QueryString}"; - - ctx.Response.OnCompleted(() => - { - _logger.LogInformation($"{ctx.Request.Method} request to {targetHost}{pathAndQuery} returned to client with code {ctx.Response.StatusCode}"); - return Task.CompletedTask; - }); - List notes; - lock (_notesForNextInteraction) - { - notes = new List(_notesForNextInteraction); - _notesForNextInteraction.Clear(); - } - await handler.HandleRequest(targetHost, pathAndQuery, ctx.Request.Method, ctx.Request.Headers, ctx.Request.ContentType, ctx.Request.Body, (code) => ctx.Response.StatusCode = (int)code, ctx.Response.Headers, ctx.Response.Body, (ct)=> ctx.Response.ContentType=ct, notes); - + _logger.LogInformation($"{ctx.Request.Method} request to {targetHost}{pathAndQuery} returned to client with code {ctx.Response.StatusCode}"); + return Task.CompletedTask; + }); + List notes; + lock (_notesForNextInteraction) + { + notes = new List(_notesForNextInteraction); + _notesForNextInteraction.Clear(); } + await handler.HandleRequest(targetHost, pathAndQuery, ctx.Request.Method, ctx.Request.Headers, ctx.Request.ContentType, ctx.Request.Body, (code) => ctx.Response.StatusCode = (int)code, ctx.Response.Headers, ctx.Response.Body, (ct)=> ctx.Response.ContentType=ct, notes); } catch (Exception ex) diff --git a/Servirtium.Core/Interactions/InteractionRecorder.cs b/Servirtium.Core/Interactions/InteractionRecorder.cs index 4ff00e6..963b4a0 100644 --- a/Servirtium.Core/Interactions/InteractionRecorder.cs +++ b/Servirtium.Core/Interactions/InteractionRecorder.cs @@ -189,6 +189,7 @@ public void NoteCompletedInteraction(int interactionNumber, IRequestMessage requ public void StartScript() { +// using (var fileContents = File.OpenText(this._targetFile)) using (var fileContents = File.OpenText("")) { //TODO: Implement loading previous script version for comparison