コード例 #1
0
 private bool ShouldCompress(HttpRequestMessage request)
 {
     return(request.Content != null &&
            !(request.Content?.Headers?.ContentEncoding?.Contains("gzip") ?? false) &&
            !(request.Content?.Headers?.ContentEncoding?.Contains("deflate") ?? false) &&
            (_RequestCondition?.ShouldProcess(request) ?? true));
 }
コード例 #2
0
        /// <summary>
        /// Applies the configured dynamic headers and passes the request on.
        /// </summary>
        /// <remarks>
        /// <para>Does not modify headers that already have a value.</para>
        /// <para>Does not create/apply headers where the function returning the value returns null.</para>
        /// </remarks>
        /// <param name="request">The request to modify and pass on.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> that can be used to cancel the request.</param>
        /// <returns>A task whose result is the <see cref="HttpResponseMessage"/> from the server.</returns>
        /// <see cref="DynamicRequestHeaderHandler"/>
        protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (_ApplyHeadersCondition?.ShouldProcess(request) ?? true)
            {
                foreach (var kvp in _DynamicHeaders)
                {
                    var value = kvp.Value();
                    if (value != null)
                    {
                        request.Headers.TryAddWithoutValidation(kvp.Key, value);
                    }

                    cancellationToken.ThrowIfCancellationRequested();
                }
            }

            return(base.SendAsync(request, cancellationToken));
        }
コード例 #3
0
 private bool ShouldAuthoriseRequest(HttpRequestMessage request, OAuth2HttpRequestSigningMethod signingMethod)
 {
     return(((signingMethod == OAuth2HttpRequestSigningMethod.AuthorizationHeader && IsAuthHeaderMissing(request.Headers.Authorization)) ||
             (signingMethod == OAuth2HttpRequestSigningMethod.UrlQuery && IsAccessTokenQueryArgumentMissing(request.RequestUri))) &&
            (_RequestCondition?.ShouldProcess(request) ?? true));
 }