Beispiel #1
0
    public static void SetupLogging(FlurlHttpSettings settings, ILogger log, Func <Url, Url>?urlInterceptor = null)
    {
        urlInterceptor ??= url => url;

        settings.BeforeCall = call =>
        {
            var url = urlInterceptor(call.Request.Url.Clone());
            log.Debug("HTTP Request: {Method} {Url}", call.HttpRequestMessage.Method, url);
        };

        settings.AfterCall = call =>
        {
            var statusCode = call.Response?.StatusCode.ToString() ?? "(No response)";
            var url        = urlInterceptor(call.Request.Url.Clone());
            log.Debug("HTTP Response: {Status} {Method} {Url}", statusCode, call.HttpRequestMessage.Method, url);
        };

        settings.OnRedirect = call =>
        {
            log.Warning("HTTP Redirect received; this indicates a problem with your URL and/or reverse proxy: {Url}",
                        call.Redirect.Url);

            call.Redirect.Follow = false;
        };
    }
Beispiel #2
0
 internal static void SetFlurlHttpCall(this HttpRequestMessage request, FlurlHttpSettings settings)
 {
     if (request?.Properties != null)
     {
         request.Properties["FlurlHttpCall"] = new HttpCall(request, settings);
     }
 }
Beispiel #3
0
        public static void ConfigureRequest(FlurlHttpSettings settings)
        {
            var jsonSettings = JsonSerializer();

            //jsonSettings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
            settings.JsonSerializer = new NewtonsoftJsonSerializer(jsonSettings);
        }
Beispiel #4
0
 internal static void Set(HttpRequestMessage request, FlurlHttpSettings settings)
 {
     if (request != null && request.Properties != null)
     {
         request.Properties["FlurlHttpCall"] = new HttpCall {
             Request = request, Settings = settings
         }
     }
     ;
 }
Beispiel #5
0
 public FakeFlurlRequest(IFlurlClient client, string route, RouteMatch routeMatch)
 {
     _url        = client.BaseUrl + "/" + route;
     _routeMatch = routeMatch;
     _client     = client;
     _headers    = new Dictionary <string, object>();
     _cookies    = new Dictionary <string, Cookie>();
     _settings   = new FlurlHttpSettings();
     _settings.JsonSerializer = new DefaultJsonSerializer();
 }
Beispiel #6
0
        public void ConfigureFlurlHttpSettings(FlurlHttpSettings settings)
        {
            var jsonSettings = new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                DateFormatString  = "yyyy-MM-dd"
            };

            jsonSettings.Converters.Add(new StringEnumConverter(true));
            settings.JsonSerializer = new NewtonsoftJsonSerializer(jsonSettings);
        }
Beispiel #7
0
        internal HttpCall(HttpRequestMessage request, FlurlHttpSettings settings)
        {
            Request = request;
            if (request?.Properties != null)
            {
                request.Properties["FlurlHttpCall"] = this;
            }

            Settings = settings;
            _url     = new Lazy <Url>(() => new Url(Request.RequestUri.AbsoluteUri));
        }
        private void ConfigureClient(FlurlHttpSettings cfg, string userKey)
        {
            cfg.BeforeCall = call =>
            {
                call.Request.Headers.Add("key_type", "3scale");
                if (string.IsNullOrEmpty(userKey))
                {
                    return;
                }
                call.Request.Headers.Add("user_key", userKey);
            };
            cfg.OnError = call =>
            {
                ErrorResponse = JsonConvert.DeserializeObject <ErrorResponse>(call.ErrorResponseBody);
            };

            cfg.AfterCall = call =>
            {
                if (!call.Succeeded)
                {
                    return;
                }

                int.TryParse(call.Response.Headers.GetValues("x-ratelimit-remaining").First(), out int remaining);
                int.TryParse(call.Response.Headers.GetValues("x-ratelimit-reset").First(), out int resetEpochSeconds);
                int.TryParse(call.Response.Headers.GetValues("x-ratelimit-limit").First(), out int limit);

                var current = 0;
                if (call.Response.Headers.TryGetValues("x-ratelimit-current", out IEnumerable <string> currents))
                {
                    int.TryParse(currents.First(), out current);
                }

                var reset = _epoch.AddSeconds(resetEpochSeconds);

                _rateLimitResponse = new RateLimitResponse
                {
                    Remaining = remaining,
                    Limit     = limit,
                    Current   = current,
                    Reset     = reset
                };
            };

            cfg.JsonSerializer = new NewtonsoftJsonSerializer(new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });
        }
Beispiel #9
0
    public static void SetupLogging(FlurlHttpSettings settings, ILogger log, Func <Url, Url>?urlInterceptor = null)
    {
        urlInterceptor ??= url => url;

        settings.BeforeCall = call =>
        {
            var url = urlInterceptor(call.Request.Url.Clone());
            log.Debug("HTTP Request to {Url}", url);
        };

        settings.AfterCall = call =>
        {
            var statusCode = call.Response?.StatusCode.ToString() ?? "(No response)";
            var url        = urlInterceptor(call.Request.Url.Clone());
            log.Debug("HTTP Response {Status} from {Url}", statusCode, url);
        };
    }
Beispiel #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FlurlRequest"/> class.
 /// </summary>
 /// <param name="url">The URL to call with this FlurlRequest instance.</param>
 public FlurlRequest(Url url = null)
 {
     Settings = new FlurlHttpSettings();
     Url      = url;
 }
Beispiel #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CapturedMultipartContent"/> class.
 /// </summary>
 /// <param name="subtype">The subtype of the multipart content.</param>
 /// <param name="boundary">The boundary string for the multipart content.</param>
 /// <param name="settings">The FlurlHttpSettings used to serialize each content part. (Defaults to FlurlHttp.GlobalSettings.)</param>
 public CapturedMultipartContent(string subtype, string boundary, FlurlHttpSettings settings = null) : base(subtype, boundary)
 {
     _settings = settings ?? FlurlHttp.GlobalSettings;
 }
 public static void SetFlurlSettings(this HttpRequestMessage request, FlurlHttpSettings settings)
 {
     request.Properties["FlurlSettings"] = settings;
 }
Beispiel #13
0
 public static MicrosoftXmlSerializer XmlSerializer(this FlurlHttpSettings settings, XmlWriterSettings xmlWriterSettings)
 {
     s_xmlWriterSettings = xmlWriterSettings;
     return(s_xmlSerializerInstance.Value);
 }
Beispiel #14
0
 internal static void SetFlurlSettings(this HttpRequestMessage request, FlurlHttpSettings settings)
 {
     request.Properties[SETTINGS_KEY] = settings;
 }
Beispiel #15
0
 public static ProtobufSerializer ProtobufSerializer(this FlurlHttpSettings settings)
 {
     return(_protoSerializerInstance.Value);
 }
Beispiel #16
0
 public static MicrosoftXmlSerializer XmlSerializer(this FlurlHttpSettings settings)
 {
     return(XmlSerializer(settings, s_xmlWriterSettings));
 }
Beispiel #17
0
 internal HttpCall(HttpRequestMessage request, FlurlHttpSettings settings)
 {
     Request  = request;
     Settings = settings;
     _url     = new Lazy <Url>(() => new Url(Request.RequestUri.AbsoluteUri));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CapturedMultipartContent"/> class.
 /// </summary>
 /// <param name="settings">The FlurlHttpSettings used to serialize each content part. (Defaults to FlurlHttp.GlobalSettings.)</param>
 public CapturedMultipartContent(FlurlHttpSettings settings = null) : base("form-data")
 {
     _settings = settings ?? FlurlHttp.GlobalSettings;
 }
Beispiel #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CapturedMultipartContent"/> class.
 /// </summary>
 /// <param name="settings">The FlurlHttpSettings used to serialize each content part.</param>
 public CapturedMultipartContent(FlurlHttpSettings settings) : base("form-data")
 {
     _settings = settings;
 }
Beispiel #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FlurlClient"/> class.
 /// </summary>
 /// <param name="settings">The FlurlHttpSettings associated with this instance.</param>
 public FlurlClient(FlurlHttpSettings settings = null)
 {
     Settings = settings ?? FlurlHttp.GlobalSettings.Clone();
 }
 /// <summary/>
 protected OpenStackNetConfigurationOptions()
 {
     _flurlHttpSettings      = new FlurlHttpSettings();
     _jsonSerializerSettings = new JsonSerializerSettings();
     _userAgents             = new List <ProductInfoHeaderValue>();
 }