/// <summary> /// Create the SabNzbClient object, here the HttpClient is configured /// </summary> /// <param name="baseUri">Base URL, e.g. https://yoursabnzbserver</param> /// <param name="apiKey">API token</param> /// <param name="httpSettings">IHttpSettings or null for default</param> public SabNzbClient(Uri baseUri, string apiKey, IHttpSettings httpSettings = null) { if (baseUri == null) { throw new ArgumentNullException(nameof(baseUri)); } _apiKey = apiKey ?? throw new ArgumentNullException(nameof(apiKey)); SabNzbApiUri = baseUri.AppendSegments("api").ExtendQuery(new Dictionary <string, string> { { "output", "json" }, { "apikey", apiKey } }); _behaviour = new HttpBehaviour { HttpSettings = httpSettings ?? HttpExtensionsGlobals.HttpSettings, JsonSerializer = new SimpleJsonSerializer(), OnHttpRequestMessageCreated = httpMessage => { if (!string.IsNullOrEmpty(_user) && _password != null) { httpMessage?.SetBasicAuthorization(_user, _password); } return(httpMessage); } }; }
public async Task TestHttpExtensionsDefaultReadWrite() { var iniFileConfig = IniFileConfigBuilder.Create() .WithApplicationName("Dapplo") .WithFilename("dapplo.httpextensions") .WithoutSaveOnExit() .BuildApplicationConfig(); // Important to disable the auto-save, otherwise we get test issues var iniConfig = new IniConfig(iniFileConfig); using (var testMemoryStream = new MemoryStream()) { await IniConfig.Current.ReadFromStreamAsync(testMemoryStream).ConfigureAwait(false); } var httpConfiguration = await iniConfig.RegisterAndGetAsync <IHttpConfiguration>(); Assert.NotNull(httpConfiguration); using (var writeStream = new MemoryStream()) { await iniConfig.WriteToStreamAsync(writeStream).ConfigureAwait(false); writeStream.Seek(0, SeekOrigin.Begin); await iniConfig.ReadFromStreamAsync(writeStream).ConfigureAwait(false); var behaviour = new HttpBehaviour { HttpSettings = httpConfiguration }; behaviour.MakeCurrent(); HttpClientFactory.Create(); } }
public ImgurOAuth2Tests(ITestOutputHelper testOutputHelper) { LogSettings.RegisterDefaultLogger <XUnitLogger>(LogLevels.Verbose, testOutputHelper); var oAuth2Settings = new OAuth2Settings { AuthorizationUri = ApiUri.AppendSegments("oauth2", "authorize"). ExtendQuery(new Dictionary <string, string> { { "response_type", "code" }, { "client_id", "{ClientId}" }, { "redirect_uri", "{RedirectUrl}" }, // TODO: Add version? { "state", "{State}" } }), TokenUrl = ApiUri.AppendSegments("oauth2", "token"), CloudServiceName = "Imgur", ClientId = ClientId, ClientSecret = ClientSecret, RedirectUrl = "https://getgreenshot.org/oauth/imgur", AuthorizeMode = AuthorizeModes.OutOfBoundAuto }; var behavior = new HttpBehaviour { JsonSerializer = new JsonNetJsonSerializer(), OnHttpClientCreated = httpClient => { httpClient.SetAuthorization("Client-ID", ClientId); httpClient.DefaultRequestHeaders.ExpectContinue = false; } }; _oAuthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(oAuth2Settings, behavior); }
public async Task TestRedirectAndNotFollow() { var behavior = new HttpBehaviour { HttpSettings = new HttpSettings() }; behavior.HttpSettings.AllowAutoRedirect = false; behavior.MakeCurrent(); await Assert.ThrowsAsync <HttpRequestException>(async() => await new Uri("https://httpbin.org/redirect/2").GetAsAsync <string>()); }
public OneDriveDestination( IOneDriveConfiguration oneDriveConfiguration, IOneDriveLanguage oneDriveLanguage, INetworkConfiguration networkConfiguration, IResourceProvider resourceProvider, Func <CancellationTokenSource, Owned <PleaseWaitForm> > pleaseWaitFormFactory, ICoreConfiguration coreConfiguration, IGreenshotLanguage greenshotLanguage ) : base(coreConfiguration, greenshotLanguage) { _oneDriveConfiguration = oneDriveConfiguration; _oneDriveLanguage = oneDriveLanguage; _resourceProvider = resourceProvider; _pleaseWaitFormFactory = pleaseWaitFormFactory; // Configure the OAuth2 settings for OneDrive communication _oauth2Settings = new OAuth2Settings { AuthorizationUri = OAuth2Uri.AppendSegments("authorize") .ExtendQuery(new Dictionary <string, string> { { "response_type", "code" }, { "client_id", "{ClientId}" }, { "redirect_uri", "{RedirectUrl}" }, { "state", "{State}" }, { "scope", "files.readwrite offline_access" } }), TokenUrl = OAuth2Uri.AppendSegments("token"), CloudServiceName = "OneDrive", ClientId = _oneDriveConfiguration.ClientId, ClientSecret = "", RedirectUrl = "https://login.microsoftonline.com/common/oauth2/nativeclient", AuthorizeMode = AuthorizeModes.EmbeddedBrowser, Token = oneDriveConfiguration }; _oneDriveHttpBehaviour = new HttpBehaviour { HttpSettings = networkConfiguration, JsonSerializer = new JsonNetJsonSerializer() }; }
/// <summary> /// Create the ConfluenceApi object, here the HttpClient is configured /// </summary> /// <param name="baseUri">Base URL, e.g. https://yourConfluenceserver</param> /// <param name="httpSettings">IHttpSettings or null for default</param> public ConfluenceApi(Uri baseUri, IHttpSettings httpSettings = null) { if (baseUri == null) { throw new ArgumentNullException(nameof(baseUri)); } ConfluenceBaseUri = baseUri.AppendSegments("rest", "api"); _behaviour = new HttpBehaviour { HttpSettings = httpSettings, OnHttpRequestMessageCreated = httpMessage => { httpMessage?.Headers.TryAddWithoutValidation("X-Atlassian-Token", "no-check"); if (!string.IsNullOrEmpty(_user) && _password != null) { httpMessage?.SetBasicAuthorization(_user, _password); } return(httpMessage); } }; }
public ImgurApi( IImgurConfiguration imgurConfiguration, ICoreConfiguration coreConfiguration, INetworkConfiguration networkConfiguration) { _imgurConfiguration = imgurConfiguration; _coreConfiguration = coreConfiguration; // Configure the OAuth2 settings for Imgur communication _oauth2Settings = new OAuth2Settings { AuthorizationUri = new Uri("https://api.imgur.com").AppendSegments("oauth2", "authorize"). ExtendQuery(new Dictionary <string, string> { { "response_type", "code" }, { "client_id", "{ClientId}" }, { "redirect_uri", "{RedirectUrl}" }, // TODO: Add version? { "state", "{State}" } }), TokenUrl = new Uri("https://api.imgur.com/oauth2/token"), CloudServiceName = "Imgur", ClientId = imgurConfiguration.ClientId, ClientSecret = imgurConfiguration.ClientSecret, RedirectUrl = "https://getgreenshot.org/oauth/imgur", AuthorizeMode = AuthorizeModes.OutOfBoundAuto, Token = imgurConfiguration }; Behaviour = new HttpBehaviour { HttpSettings = networkConfiguration, JsonSerializer = new JsonNetJsonSerializer(), OnHttpClientCreated = httpClient => { httpClient.SetAuthorization("Client-ID", _imgurConfiguration.ClientId); httpClient.DefaultRequestHeaders.ExpectContinue = false; } }; }
public TfsClient( ICoreConfiguration coreConfiguration, ITfsConfiguration tfsConfiguration, INetworkConfiguration networkConfiguration) { _coreConfiguration = coreConfiguration; _tfsConfiguration = tfsConfiguration; _tfsHttpBehaviour = new HttpBehaviour { HttpSettings = networkConfiguration, JsonSerializer = new JsonNetJsonSerializer() }; #if DEBUG // Set json log threshold high _tfsHttpBehaviour.RequestConfigurations[nameof(DefaultJsonHttpContentConverterConfiguration)] = new DefaultJsonHttpContentConverterConfiguration { LogThreshold = 0 }; #endif }
/// <summary> /// Create the ServiceNowApi object, here the HttpClient is configured /// </summary> /// <param name="baseUri">Base URL, e.g. https://servicenow</param> /// <param name="httpSettings">IHttpSettings or null for default</param> public ServiceNowApi(Uri baseUri, IHttpSettings httpSettings = null) { if (baseUri == null) { throw new ArgumentNullException(nameof(baseUri)); } BaseUri = baseUri.AppendSegments("api", "now"); _behaviour = new HttpBehaviour { HttpSettings = httpSettings ?? HttpExtensionsGlobals.HttpSettings, OnHttpRequestMessageCreated = httpMessage => { if (!string.IsNullOrEmpty(_user) && _password != null) { httpMessage?.SetBasicAuthorization(_user, _password); } if (!string.IsNullOrEmpty(_userToken)) { httpMessage?.AddRequestHeader("X-UserToken", _userToken); } return(httpMessage); } }; }
// // constructors // internal ServicePoint(Uri address, TimerThread.Queue defaultIdlingQueue, int defaultConnectionLimit, string lookupString, bool userChangedLimit, bool proxyServicePoint) { GlobalLog.Print("ServicePoint#" + ValidationHelper.HashString(this) + "::.ctor(" + lookupString+")"); if (Logging.On) Logging.Enter(Logging.Web, this, "ServicePoint", address.DnsSafeHost + ":" + address.Port); m_ProxyServicePoint = proxyServicePoint; m_Address = address; m_ConnectionName = address.Scheme; m_Host = address.DnsSafeHost; m_Port = address.Port; m_IdlingQueue = defaultIdlingQueue; m_ConnectionLimit = defaultConnectionLimit; m_HostLoopbackGuess = TriState.Unspecified; m_LookupString = lookupString; m_UserChangedLimit = userChangedLimit; m_UseNagleAlgorithm = ServicePointManager.UseNagleAlgorithm; m_Expect100Continue = ServicePointManager.Expect100Continue; m_ConnectionGroupList = new Hashtable(10); m_ConnectionLeaseTimeout = System.Threading.Timeout.Infinite; m_ReceiveBufferSize = -1; m_UseTcpKeepAlive = ServicePointManager.s_UseTcpKeepAlive; m_TcpKeepAliveTime = ServicePointManager.s_TcpKeepAliveTime; m_TcpKeepAliveInterval = ServicePointManager.s_TcpKeepAliveInterval; // it would be safer to make sure the server is 1.1 // but assume it is at the beginning, and update it later m_Understands100Continue = true; m_HttpBehaviour = HttpBehaviour.Unknown; // upon creation, the service point should be idle, by default m_IdleSince = DateTime.Now; m_ExpiringTimer = m_IdlingQueue.CreateTimer(ServicePointManager.IdleServicePointTimeoutDelegate, this); m_IdleConnectionGroupTimeoutDelegate = new TimerThread.Callback(IdleConnectionGroupTimeoutCallback); }
public async Task TestRedirectAndNotFollow() { var behavior = new HttpBehaviour { HttpSettings = new HttpSettings() }; behavior.HttpSettings.AllowAutoRedirect = false; behavior.MakeCurrent(); await Assert.ThrowsAsync<HttpRequestException>(async () => await new Uri("https://httpbin.org/redirect/2").GetAsAsync<string>()); }