Skip to content

Commit

Permalink
remove custom optons logic
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-hammant committed Sep 25, 2022
1 parent 5feddc2 commit 59ccb11
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
38 changes: 12 additions & 26 deletions Servirtium.AspNetCore/AspNetCoreServirtiumServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IInteraction.Note> notes;
lock (_notesForNextInteraction)
{
notes = new List<IInteraction.Note>(_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<IInteraction.Note> notes;
lock (_notesForNextInteraction)
{
notes = new List<IInteraction.Note>(_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)
Expand Down
1 change: 1 addition & 0 deletions Servirtium.Core/Interactions/InteractionRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 59ccb11

Please sign in to comment.