/// <summary> /// Helper method to configure the IChangeableHttpBehaviour /// </summary> /// <param name="behaviour">IChangeableHttpBehaviour</param> /// <param name="httpSettings">IHttpSettings</param> /// <returns>the behaviour, but configured as IHttpBehaviour </returns> private IHttpBehaviour ConfigureBehaviour(IChangeableHttpBehaviour behaviour, IHttpSettings httpSettings = null) { #if NET45 || NET46 // Add SvgBitmapHttpContentConverter if it was not yet added if (HttpExtensionsGlobals.HttpContentConverters.All(x => x.GetType() != typeof(SvgBitmapHttpContentConverter))) { HttpExtensionsGlobals.HttpContentConverters.Add(SvgBitmapHttpContentConverter.Instance.Value); } #endif behaviour.HttpSettings = httpSettings ?? HttpExtensionsGlobals.HttpSettings.ShallowClone(); #if NET45 || NET46 // Disable caching, if no HTTP settings were provided. if (httpSettings == null) { behaviour.HttpSettings.RequestCacheLevel = RequestCacheLevel.NoCacheNoStore; } #endif // Using our own Json Serializer, implemented with Json.NET behaviour.JsonSerializer = new JsonNetJsonSerializer(); behaviour.OnHttpRequestMessageCreated = httpMessage => { httpMessage?.Headers.TryAddWithoutValidation("X-Atlassian-Token", "nocheck"); if (!string.IsNullOrEmpty(_user) && _password != null) { httpMessage?.SetBasicAuthorization(_user, _password); } return(httpMessage); }; return(behaviour); }
/// <summary> /// Helper method to configure the IChangeableHttpBehaviour /// </summary> /// <param name="behaviour">IChangeableHttpBehaviour</param> /// <param name="httpSettings">IHttpSettings</param> /// <returns>the behaviour, but configured as IHttpBehaviour </returns> protected IHttpBehaviour ConfigureBehaviour(IChangeableHttpBehaviour behaviour, IHttpSettings httpSettings = null) { behaviour.HttpSettings = httpSettings ?? HttpExtensionsGlobals.HttpSettings; #if NET471 || NET461 // Disable caching, if no HTTP settings were provided. // This is needed as was detected here: https://github.com/dapplo/Dapplo.Confluence/issues/11 if (httpSettings == null) { behaviour.HttpSettings.RequestCacheLevel = RequestCacheLevel.NoCacheNoStore; } #endif // Using our own Json Serializer, implemented with JsonNetJsonSerializer behaviour.JsonSerializer = CreateJsonNetJsonSerializer(); behaviour.OnHttpRequestMessageCreated = httpMessage => { httpMessage?.Headers.TryAddWithoutValidation("X-Atlassian-Token", "no-check"); if (!string.IsNullOrEmpty(_user) && _password != null) { httpMessage?.SetBasicAuthorization(_user, _password); } return(httpMessage); }; return(behaviour); }
/// <summary> /// Helper method to configure the IChangeableHttpBehaviour /// </summary> /// <param name="behaviour">IChangeableHttpBehaviour</param> /// <param name="httpSettings">IHttpSettings</param> /// <returns>the behaviour, but configured as IHttpBehaviour </returns> public IHttpBehaviour ConfigureBehaviour(IChangeableHttpBehaviour behaviour, IHttpSettings httpSettings = null) { behaviour.HttpSettings = httpSettings ?? HttpExtensionsGlobals.HttpSettings.ShallowClone(); #if NET461 // Disable caching, if no HTTP settings were provided. if (httpSettings == null) { behaviour.HttpSettings.RequestCacheLevel = RequestCacheLevel.NoCacheNoStore; } #endif // Using our own Json Serializer, implemented with Json.NET behaviour.JsonSerializer = new JsonNetJsonSerializer(); behaviour.OnHttpRequestMessageCreated = httpMessage => { httpMessage?.Headers.TryAddWithoutValidation("X-Atlassian-Token", "nocheck"); if (!string.IsNullOrEmpty(_user) && _password != null) { httpMessage?.SetBasicAuthorization(_user, _password); } return(httpMessage); }; return(behaviour); }
/// <summary> /// Helper method to configure the IChangeableHttpBehaviour /// </summary> /// <param name="behaviour">IChangeableHttpBehaviour</param> /// <param name="httpSettings">IHttpSettings</param> /// <returns>the behaviour, but configured as IHttpBehaviour </returns> private IHttpBehaviour ConfigureBehaviour(IChangeableHttpBehaviour behaviour, IHttpSettings httpSettings = null) { behaviour.HttpSettings = httpSettings ?? HttpExtensionsGlobals.HttpSettings; behaviour.OnHttpRequestMessageCreated = httpMessage => { httpMessage?.Headers.TryAddWithoutValidation("X-Atlassian-Token", "no-check"); if (!string.IsNullOrEmpty(_user) && _password != null) { httpMessage?.SetBasicAuthorization(_user, _password); } return(httpMessage); }; return(behaviour); }
/// <summary> /// Chain the current OnHttpRequestMessageCreated function /// </summary> /// <param name="changeableHttpBehaviour">IChangeableHttpBehaviour</param> /// <param name="newOnHttpRequestMessageCreated">Function which accepts and returns HttpRequestMessage</param> /// <returns>IChangeableHttpBehaviour for fluent usage</returns> public static IChangeableHttpBehaviour ChainOnHttpRequestMessageCreated(this IChangeableHttpBehaviour changeableHttpBehaviour, Func <HttpRequestMessage, HttpRequestMessage> newOnHttpRequestMessageCreated) { var onHttpRequestMessageCreated = changeableHttpBehaviour.OnHttpRequestMessageCreated; changeableHttpBehaviour.OnHttpRequestMessageCreated = httpRequestMessage => { if (onHttpRequestMessageCreated != null) { httpRequestMessage = onHttpRequestMessageCreated(httpRequestMessage); } return(newOnHttpRequestMessageCreated(httpRequestMessage)); }; return(changeableHttpBehaviour); }
/// <summary> /// Chain the current OnHttpMessageHandlerCreated /// </summary> /// <param name="changeableHttpBehaviour"></param> /// <param name="newOnHttpMessageHandlerCreated">function which accepts a HttpMessageHandler and also returns one</param> /// <returns>IChangeableHttpBehaviour for fluent usage</returns> public static IChangeableHttpBehaviour ChainOnHttpMessageHandlerCreated(this IChangeableHttpBehaviour changeableHttpBehaviour, Func <HttpMessageHandler, HttpMessageHandler> newOnHttpMessageHandlerCreated) { var oldOnHttpMessageHandlerCreated = changeableHttpBehaviour.OnHttpMessageHandlerCreated; changeableHttpBehaviour.OnHttpMessageHandlerCreated = httpMessageHandler => { if (oldOnHttpMessageHandlerCreated != null) { httpMessageHandler = oldOnHttpMessageHandlerCreated(httpMessageHandler); } return(newOnHttpMessageHandlerCreated(httpMessageHandler)); }; return(changeableHttpBehaviour); }
/// <summary> /// Chain the current OnHttpContentCreated /// </summary> /// <param name="changeableHttpBehaviour"></param> /// <param name="newOnHttpContentCreated"></param> /// <returns>IChangeableHttpBehaviour for fluent usage</returns> public static IChangeableHttpBehaviour ChainOnHttpContentCreated(this IChangeableHttpBehaviour changeableHttpBehaviour, Func <HttpContent, HttpContent> newOnHttpContentCreated) { var oldOnHttpContentCreated = changeableHttpBehaviour.OnHttpContentCreated; changeableHttpBehaviour.OnHttpContentCreated = httpContent => { if (oldOnHttpContentCreated != null) { httpContent = oldOnHttpContentCreated(httpContent); } return(newOnHttpContentCreated(httpContent)); }; return(changeableHttpBehaviour); }
/// <summary>Factory method to create the jira client</summary> //public static IWorklogService Create(Uri baseUri, IHttpSettings httpSettings = null) //{ // return (IWorklogService)new WorklogService(baseUri, httpSettings); //} /// <summary> /// Helper method to configure the IChangeableHttpBehaviour /// </summary> /// <param name="behaviour">IChangeableHttpBehaviour</param> /// <param name="httpSettings">IHttpSettings</param> /// <returns>the behaviour, but configured as IHttpBehaviour </returns> private IHttpBehaviour ConfigureBehaviour(IChangeableHttpBehaviour behaviour, IHttpSettings httpSettings = null) { behaviour.HttpSettings = httpSettings ?? HttpExtensionsGlobals.HttpSettings; behaviour.JsonSerializer = (IJsonSerializer) new JsonNetJsonSerializer(); behaviour.OnHttpRequestMessageCreated = (Func <HttpRequestMessage, HttpRequestMessage>)(httpMessage => { if (httpMessage != null) { httpMessage.Headers.TryAddWithoutValidation("X-Atlassian-Token", "nocheck"); } if (!string.IsNullOrEmpty(this._user) && this._password != null && httpMessage != null) { httpMessage.SetBasicAuthorization(this._user, this._password); } return(httpMessage); }); return((IHttpBehaviour)behaviour); }
/// <summary> /// Helper method to configure the IChangeableHttpBehaviour /// </summary> /// <param name="behaviour">IChangeableHttpBehaviour</param> /// <param name="httpSettings">IHttpSettings</param> /// <returns>the behaviour, but configured as IHttpBehaviour </returns> private IHttpBehaviour ConfigureBehaviour(IChangeableHttpBehaviour behaviour, IHttpSettings httpSettings = null) { #if NET45 || NET46 if (HttpExtensionsGlobals.HttpContentConverters.All(x => x.GetType() != typeof(SvgBitmapHttpContentConverter))) { HttpExtensionsGlobals.HttpContentConverters.Add(SvgBitmapHttpContentConverter.Instance.Value); } #endif behaviour.HttpSettings = httpSettings ?? HttpExtensionsGlobals.HttpSettings; behaviour.OnHttpRequestMessageCreated = httpMessage => { httpMessage?.Headers.TryAddWithoutValidation("X-Atlassian-Token", "nocheck"); if (!string.IsNullOrEmpty(_user) && _password != null) { httpMessage?.SetBasicAuthorization(_user, _password); } return(httpMessage); }; return(behaviour); }
/// <summary> /// Create a OAuthHttpBehaviour /// </summary> /// <param name="httpBehaviour">IHttpBehaviour to wrap</param> public OAuth1HttpBehaviour(IHttpBehaviour httpBehaviour = null) { _wrapped = (httpBehaviour ?? HttpBehaviour.Current).ShallowClone(); }