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; }; }
internal static void SetFlurlHttpCall(this HttpRequestMessage request, FlurlHttpSettings settings) { if (request?.Properties != null) { request.Properties["FlurlHttpCall"] = new HttpCall(request, settings); } }
public static void ConfigureRequest(FlurlHttpSettings settings) { var jsonSettings = JsonSerializer(); //jsonSettings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb); settings.JsonSerializer = new NewtonsoftJsonSerializer(jsonSettings); }
internal static void Set(HttpRequestMessage request, FlurlHttpSettings settings) { if (request != null && request.Properties != null) { request.Properties["FlurlHttpCall"] = new HttpCall { Request = request, Settings = settings } } ; }
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(); }
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); }
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() }); }
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); }; }
/// <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; }
/// <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; }
public static MicrosoftXmlSerializer XmlSerializer(this FlurlHttpSettings settings, XmlWriterSettings xmlWriterSettings) { s_xmlWriterSettings = xmlWriterSettings; return(s_xmlSerializerInstance.Value); }
internal static void SetFlurlSettings(this HttpRequestMessage request, FlurlHttpSettings settings) { request.Properties[SETTINGS_KEY] = settings; }
public static ProtobufSerializer ProtobufSerializer(this FlurlHttpSettings settings) { return(_protoSerializerInstance.Value); }
public static MicrosoftXmlSerializer XmlSerializer(this FlurlHttpSettings settings) { return(XmlSerializer(settings, s_xmlWriterSettings)); }
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; }
/// <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; }
/// <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>(); }