Exemple #1
0
 /// <summary>
 /// Add all from fluent HTTP headers.
 /// </summary>
 /// <param name="headers">Headers to add to.</param>
 /// <param name="values">Headers to add from.</param>
 public static void AddRange(this HttpHeaders headers, FluentHttpHeaders values)
 {
     foreach (var headerEntry in values)
     {
         headers.Add(headerEntry.Key, (IEnumerable <string>)headerEntry.Value);
     }
 }
        /// <summary>
        /// Generate request hash.
        /// </summary>
        /// <param name="request">Request to generate hash for.</param>
        internal static string GenerateHash(this FluentHttpRequest request)
        {
            var options = request.GetRequestHashOptions();

            var headers = new FluentHttpHeaders(request.Builder.DefaultHeaders)
                          .SetRange(request.Headers);

            if (options?.HeadersExclude != null)
            {
                headers.WithOptions(opts => opts.WithHashingExclude(options.HeadersExclude));
            }

            var headersHash = headers.ToHashString();

            var uri = request.Uri.IsAbsoluteUri
                                ? request.Uri
                                : new Uri($"{request.Builder.BaseUrl.TrimEnd('/')}/{request.Uri.ToString().TrimStart('/')}");

            var uriHash = options?.UriManipulation == null
                                ? uri.ToString()
                                : options.UriManipulation.Invoke(uri);

            var contentHash = string.Empty;

            if (request.Message.Content is ObjectContent c)
            {
                contentHash = options?.HashBody?.Invoke(c.Value) ?? JsonConvert.SerializeObject(c.Value);
            }

            return($"method={request.Method};url={uriHash};headers={headersHash};content={contentHash}");
        }
 /// <inheritdoc />
 public FluentHttpRequestBuilder WithHeader(string key, string value)
 {
     if (Headers == null)
     {
         Headers = new FluentHttpHeaders();
     }
     Headers[key] = value;
     return(this);
 }
 /// <inheritdoc />
 public FluentHttpRequestBuilder WithHeaders(IDictionary <string, StringValues> headers)
 {
     if (Headers == null)
     {
         Headers = new FluentHttpHeaders();
     }
     Headers.SetRange(headers);
     return(this);
 }
 /// <inheritdoc />
 public FluentHttpRequestBuilder WithHeaders(FluentHttpHeaders headers)
 {
     Headers.SetRange(headers);
     return(this);
 }
Exemple #6
0
 /// <inheritdoc />
 public FluentHttpClientBuilder WithHeaders(FluentHttpHeaders headers)
 {
     _headers.SetRange(headers);
     return(this);
 }