public static string GetKey(Request request, CassetteOptions options) { if (request.Headers.ContainsKey(CassetteOptions.NoRecord)) { return(null); } string requestMethod = request.Method; string requestUri = request.Headers.ContainsKey(CassetteOptions.ExcludeLastUriSegment) ? request.GetUriWithoutLastSegment() : request.Uri; using (var hasher = IncrementalHash.CreateHash(HashAlgorithmName.SHA1)) { hasher.AppendData(Encoding.UTF8.GetBytes(requestMethod + requestUri)); if (request.Body != null && !request.Headers.ContainsKey(CassetteOptions.ExcludeRequestBody)) { hasher.AppendData(request.Body); } return(options.KeyPrefix is null ? "" : options.KeyPrefix + options.KeySeparator + requestMethod + options.KeySeparator + requestUri.Replace("http://", "http//").Replace("https://", "https//") + options.KeySeparator + Convert.ToBase64String(hasher.GetHashAndReset())); } }
public static async Task<string> GetCassetteKey(this HttpRequestMessage httpRequest, CassetteOptions options) { var request = await httpRequest.ToRequest(); return Cassette.GetKey(request, options); }
/// <summary> /// Initializes a new instance of the <see cref="ReplayingHandler"/>. /// </summary> /// <param name="cache"> The distributed cache used by Cassette to store successful HTTP response messages that went through this handler. </param> /// <param name="options"> The options class for configuring Cassette. </param> /// <param name="logger"> A dedicated logger. </param> public ReplayingHandler(IDistributedCache cache, IOptions <CassetteOptions> options, ILogger <ReplayingHandler> logger) { _cache = cache ?? throw new ArgumentNullException(nameof(cache)); _options = (options ?? throw new ArgumentNullException(nameof(options))).Value; _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }