mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-24 01:38:53 +02:00
goed
This commit is contained in:
@@ -18,7 +18,7 @@ public class LogRequestModel
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The DateTime.
|
/// The DateTime.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime DateTime { get; set; }
|
public required DateTime DateTime { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Path.
|
/// The Path.
|
||||||
@@ -58,7 +58,7 @@ public class LogRequestModel
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The HTTP Version.
|
/// The HTTP Version.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string HttpVersion { get; set; } = null!;
|
public string? HttpVersion { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Headers.
|
/// The Headers.
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
|
|
||||||
@@ -80,4 +79,14 @@ public class LogResponseModel
|
|||||||
/// Gets or sets the Fault percentage.
|
/// Gets or sets the Fault percentage.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double? FaultPercentage { get; set; }
|
public double? FaultPercentage { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The DateTime.
|
||||||
|
/// </summary>
|
||||||
|
public required DateTime DateTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The method.
|
||||||
|
/// </summary>
|
||||||
|
public string? Method { get; set; }
|
||||||
}
|
}
|
||||||
@@ -56,6 +56,11 @@ public interface IResponseMessage
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
DateTime DateTime { get; }
|
DateTime DateTime { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the method.
|
||||||
|
/// </summary>
|
||||||
|
string? Method { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the header.
|
/// Adds the header.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -52,23 +52,23 @@ internal class WireMockMiddlewareLogger(
|
|||||||
|
|
||||||
public void LogLogEntry(LogEntry entry, bool addRequest)
|
public void LogLogEntry(LogEntry entry, bool addRequest)
|
||||||
{
|
{
|
||||||
if (entry.RequestMessage != null)
|
_options.Logger.DebugRequestResponse(_logEntryMapper.Map(entry), entry.RequestMessage?.Path.StartsWith("/__admin/") == true);
|
||||||
{
|
|
||||||
_options.Logger.DebugRequestResponse(_logEntryMapper.Map(entry), entry.RequestMessage.Path.StartsWith("/__admin/"));
|
|
||||||
|
|
||||||
// If addRequest is set to true and MaxRequestLogCount is null or does have a value greater than 0, try to add a new request log.
|
// If addRequest is set to true and MaxRequestLogCount is null or does have a value greater than 0, try to add a new request log.
|
||||||
if (addRequest && _options.MaxRequestLogCount is null or > 0)
|
if (addRequest && _options.MaxRequestLogCount is null or > 0)
|
||||||
{
|
{
|
||||||
TryAddLogEntry(entry);
|
TryAddLogEntry(entry);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// In case MaxRequestLogCount has a value greater than 0, try to delete existing request logs based on the count.
|
// In case MaxRequestLogCount has a value greater than 0, try to delete existing request logs based on the count.
|
||||||
if (_options.MaxRequestLogCount is > 0)
|
if (_options.MaxRequestLogCount is > 0)
|
||||||
{
|
{
|
||||||
var logEntries = _options.LogEntries.Where(le => le.RequestMessage != null).ToList();
|
var logEntries = _options.LogEntries.ToList();
|
||||||
|
|
||||||
foreach (var logEntry in logEntries.OrderBy(le => le.RequestMessage!.DateTime).Take(logEntries.Count - _options.MaxRequestLogCount.Value))
|
foreach (var logEntry in logEntries
|
||||||
|
.OrderBy(le => le.RequestMessage?.DateTime ?? le.ResponseMessage?.DateTime)
|
||||||
|
.Take(logEntries.Count - _options.MaxRequestLogCount.Value))
|
||||||
{
|
{
|
||||||
TryRemoveLogEntry(logEntry);
|
TryRemoveLogEntry(logEntry);
|
||||||
}
|
}
|
||||||
@@ -77,10 +77,10 @@ internal class WireMockMiddlewareLogger(
|
|||||||
// In case RequestLogExpirationDuration has a value greater than 0, try to delete existing request logs based on the date.
|
// In case RequestLogExpirationDuration has a value greater than 0, try to delete existing request logs based on the date.
|
||||||
if (_options.RequestLogExpirationDuration is > 0)
|
if (_options.RequestLogExpirationDuration is > 0)
|
||||||
{
|
{
|
||||||
var logEntries = _options.LogEntries.Where(le => le.RequestMessage != null).ToList();
|
var logEntries = _options.LogEntries.ToList();
|
||||||
|
|
||||||
var checkTime = DateTime.UtcNow.AddHours(-_options.RequestLogExpirationDuration.Value);
|
var checkTime = DateTime.UtcNow.AddHours(-_options.RequestLogExpirationDuration.Value);
|
||||||
foreach (var logEntry in logEntries.Where(le => le.RequestMessage!.DateTime < checkTime))
|
foreach (var logEntry in logEntries.Where(le => le.RequestMessage?.DateTime < checkTime || le.ResponseMessage?.DateTime < checkTime))
|
||||||
{
|
{
|
||||||
TryRemoveLogEntry(logEntry);
|
TryRemoveLogEntry(logEntry);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ public class ResponseMessage : IResponseMessage
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTime DateTime { get; set; }
|
public DateTime DateTime { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string? Method { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void AddHeader(string name, string value)
|
public void AddHeader(string name, string value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -565,7 +565,7 @@ internal class WebSocketResponseProvider(WebSocketBuilder builder) : IResponsePr
|
|||||||
bodyData = new BodyData
|
bodyData = new BodyData
|
||||||
{
|
{
|
||||||
BodyAsString = messageType.ToString(),
|
BodyAsString = messageType.ToString(),
|
||||||
DetectedBodyType = BodyType.Bytes
|
DetectedBodyType = BodyType.String
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -595,16 +595,13 @@ internal class WebSocketResponseProvider(WebSocketBuilder builder) : IResponsePr
|
|||||||
// Sent message - log as response
|
// Sent message - log as response
|
||||||
responseMessage = new ResponseMessage
|
responseMessage = new ResponseMessage
|
||||||
{
|
{
|
||||||
|
Method = method,
|
||||||
StatusCode = HttpStatusCode.SwitchingProtocols, // WebSocket status
|
StatusCode = HttpStatusCode.SwitchingProtocols, // WebSocket status
|
||||||
BodyData = bodyData,
|
BodyData = bodyData,
|
||||||
DateTime = DateTime.UtcNow
|
DateTime = DateTime.UtcNow
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a perfect match result
|
|
||||||
var requestMatchResult = new RequestMatchResult();
|
|
||||||
requestMatchResult.AddScore(typeof(WebSocketMessageDirection), MatchScores.Perfect, null);
|
|
||||||
|
|
||||||
// Create log entry
|
// Create log entry
|
||||||
var logEntry = new LogEntry
|
var logEntry = new LogEntry
|
||||||
{
|
{
|
||||||
@@ -612,8 +609,7 @@ internal class WebSocketResponseProvider(WebSocketBuilder builder) : IResponsePr
|
|||||||
RequestMessage = requestMessage,
|
RequestMessage = requestMessage,
|
||||||
ResponseMessage = responseMessage,
|
ResponseMessage = responseMessage,
|
||||||
MappingGuid = context.Mapping.Guid,
|
MappingGuid = context.Mapping.Guid,
|
||||||
MappingTitle = context.Mapping.Title,
|
MappingTitle = context.Mapping.Title
|
||||||
RequestMatchResult = requestMatchResult
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Enrich activity if present
|
// Enrich activity if present
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ internal class LogEntryMapper(IWireMockMiddlewareOptions options)
|
|||||||
{
|
{
|
||||||
logResponseModel = new LogResponseModel
|
logResponseModel = new LogResponseModel
|
||||||
{
|
{
|
||||||
|
DateTime = logEntry.ResponseMessage.DateTime,
|
||||||
|
Method = logEntry.ResponseMessage.Method,
|
||||||
StatusCode = logEntry.ResponseMessage.StatusCode,
|
StatusCode = logEntry.ResponseMessage.StatusCode,
|
||||||
Headers = logEntry.ResponseMessage.Headers
|
Headers = logEntry.ResponseMessage.Headers
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ using System.Net.WebSockets;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
using WireMock.Extensions;
|
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
@@ -167,7 +166,7 @@ public class WireMockWebSocketContext : IWebSocketContext
|
|||||||
bodyData = new BodyData
|
bodyData = new BodyData
|
||||||
{
|
{
|
||||||
BodyAsString = messageType.ToString(),
|
BodyAsString = messageType.ToString(),
|
||||||
DetectedBodyType = BodyType.Bytes
|
DetectedBodyType = BodyType.String
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,16 +196,13 @@ public class WireMockWebSocketContext : IWebSocketContext
|
|||||||
// Sent message - log as response
|
// Sent message - log as response
|
||||||
responseMessage = new ResponseMessage
|
responseMessage = new ResponseMessage
|
||||||
{
|
{
|
||||||
|
Method = method,
|
||||||
StatusCode = HttpStatusCode.SwitchingProtocols, // WebSocket status
|
StatusCode = HttpStatusCode.SwitchingProtocols, // WebSocket status
|
||||||
BodyData = bodyData,
|
BodyData = bodyData,
|
||||||
DateTime = DateTime.UtcNow
|
DateTime = DateTime.UtcNow
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a perfect match result
|
|
||||||
var requestMatchResult = new RequestMatchResult();
|
|
||||||
requestMatchResult.AddScore(typeof(WebSocketMessageDirection), MatchScores.Perfect, null);
|
|
||||||
|
|
||||||
// Create log entry
|
// Create log entry
|
||||||
var logEntry = new LogEntry
|
var logEntry = new LogEntry
|
||||||
{
|
{
|
||||||
@@ -214,8 +210,7 @@ public class WireMockWebSocketContext : IWebSocketContext
|
|||||||
RequestMessage = requestMessage,
|
RequestMessage = requestMessage,
|
||||||
ResponseMessage = responseMessage,
|
ResponseMessage = responseMessage,
|
||||||
MappingGuid = Mapping.Guid,
|
MappingGuid = Mapping.Guid,
|
||||||
MappingTitle = Mapping.Title,
|
MappingTitle = Mapping.Title
|
||||||
RequestMatchResult = requestMatchResult
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Enrich activity if present
|
// Enrich activity if present
|
||||||
|
|||||||
Reference in New Issue
Block a user