/// <summary> /// Constructs a web request to create a new queue. /// </summary> /// <param name="uri">The absolute URI to the queue.</param> /// <param name="timeout">The server timeout interval.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object for tracking the current operation.</param> /// <returns>A web request to use to perform the operation.</returns> public static HttpWebRequest Create(Uri uri, int?timeout, OperationContext operationContext) { return(HttpWebRequestFactory.Create(uri, timeout, null, operationContext)); }
private void BuildRuntimePipeline() { #if BCL var httpRequestFactory = new HttpWebRequestFactory(new AmazonSecurityProtocolManager()); var httpHandler = new HttpHandler <Stream>(httpRequestFactory, this); #else var httpRequestFactory = new HttpRequestMessageFactory(this.Config); var httpHandler = new HttpHandler <System.Net.Http.HttpContent>(httpRequestFactory, this); #endif var preMarshallHandler = new CallbackHandler(); preMarshallHandler.OnPreInvoke = this.ProcessPreRequestHandlers; var postMarshallHandler = new CallbackHandler(); postMarshallHandler.OnPreInvoke = this.ProcessRequestHandlers; var postUnmarshallHandler = new CallbackHandler(); postUnmarshallHandler.OnPostInvoke = this.ProcessResponseHandlers; var errorCallbackHandler = new ErrorCallbackHandler(); errorCallbackHandler.OnError = this.ProcessExceptionHandlers; //Determine which retry policy to use based on the retry mode RetryPolicy retryPolicy; switch (this.Config.RetryMode) { case RequestRetryMode.Adaptive: retryPolicy = new AdaptiveRetryPolicy(this.Config); break; case RequestRetryMode.Standard: retryPolicy = new StandardRetryPolicy(this.Config); break; case RequestRetryMode.Legacy: retryPolicy = new DefaultRetryPolicy(this.Config); break; default: throw new InvalidOperationException("Unknown retry mode"); } // Build default runtime pipeline. this.RuntimePipeline = new RuntimePipeline(new List <IPipelineHandler> { httpHandler, new Unmarshaller(this.SupportResponseLogging), new ErrorHandler(_logger), postUnmarshallHandler, new Signer(), //EndpointDiscoveryResolver must come after CredentialsRetriever, RetryHander, and EndpointResolver as it depends on //credentials, retrying of requests for 421 web exceptions, and the current set regional endpoint. new EndpointDiscoveryHandler(), new CredentialsRetriever(this.Credentials), new RetryHandler(retryPolicy), postMarshallHandler, new EndpointResolver(), new Marshaller(), preMarshallHandler, errorCallbackHandler, new MetricsHandler() }, _logger ); if (DeterminedCSMConfiguration.Instance.CSMConfiguration.Enabled && !string.IsNullOrEmpty(ServiceMetadata.ServiceId)) { this.RuntimePipeline.AddHandlerBefore <ErrorHandler>(new CSMCallAttemptHandler()); this.RuntimePipeline.AddHandlerBefore <MetricsHandler>(new CSMCallEventHandler()); } CustomizeRuntimePipeline(this.RuntimePipeline); // Apply global pipeline customizations RuntimePipelineCustomizerRegistry.Instance.ApplyCustomizations(this.GetType(), this.RuntimePipeline); }
/// <summary> /// Adds user-defined metadata to the request as a single name-value pair. /// </summary> /// <param name="request">The web request.</param> /// <param name="name">The metadata name.</param> /// <param name="value">The metadata value.</param> public static void AddMetadata(HttpWebRequest request, string name, string value) { HttpWebRequestFactory.AddMetadata(request, name, value); }
public void Test() { IHttpRequestFactory<Stream> factory = new HttpWebRequestFactory(); var request = factory.CreateHttpRequest(new Uri(@"https://testuri")); Assert.IsNotNull(request); request.Method = "PUT"; var httpWebRequest = ((HttpRequest)request).Request; Assert.AreEqual("PUT", httpWebRequest.Method); var putObjectRequest = new PutObjectRequest { BucketName = "TestBucket", Key = "TestKey", ContentBody = "Test_Content", }; var proxyCreds = new System.Net.NetworkCredential("UserName","Password"); var requestContext = new RequestContext(true) { ClientConfig = new AmazonS3Config { ConnectionLimit = 10, MaxIdleTime = 1000, ProxyCredentials = proxyCreds, ProxyHost = "proxyhost", ProxyPort = 8080, ReadWriteTimeout = TimeSpan.FromSeconds(20), Timeout = TimeSpan.FromSeconds(40), UseNagleAlgorithm = false, }, Marshaller = new PutObjectRequestMarshaller(), OriginalRequest = putObjectRequest, Request = new PutObjectRequestMarshaller().Marshall(putObjectRequest), Unmarshaller = new PutObjectResponseUnmarshaller() }; request.ConfigureRequest(requestContext); Assert.IsInstanceOfType(httpWebRequest.Proxy, typeof(WebProxy)); Assert.AreEqual(new Uri("http://proxyhost:8080"), ((WebProxy)httpWebRequest.Proxy).Address); Assert.AreEqual(proxyCreds, httpWebRequest.Proxy.Credentials); Assert.AreEqual(40000, httpWebRequest.Timeout); Assert.AreEqual(20000, httpWebRequest.ReadWriteTimeout); Assert.AreEqual(1000, httpWebRequest.ServicePoint.MaxIdleTime); Assert.AreEqual(false, httpWebRequest.ServicePoint.UseNagleAlgorithm); var date = DateTime.Now.ToUniversalTime(); request.SetRequestHeaders(new Dictionary<string, string> { {"Accept","text/plain"}, //{"Connection","Keep-Alive"}, {"Content-Type","application/json"}, {"Content-Length","100"}, //{"Expect","100-continue"}, {"User-Agent","awssdk"}, {"Date",date.ToString("r")}, //{"Host","s3.amazonaws.com"}, {"Range","bytes=100-200"}, {"Content-Range","bytes 100-300/*"}, {"If-Modified-Since",date.ToString("r")}, {"Expires",date.ToString("r")}, {"NonStandardHeader","TestValue"}, }); Assert.AreEqual("text/plain", httpWebRequest.Accept); Assert.AreEqual("application/json", httpWebRequest.ContentType); Assert.AreEqual(100, httpWebRequest.ContentLength); Assert.AreEqual("awssdk", httpWebRequest.UserAgent); Assert.AreEqual(DateTime.Parse(date.ToString("r")), httpWebRequest.Date); Assert.AreEqual("testuri", httpWebRequest.Host); Assert.AreEqual(DateTime.Parse(date.ToString("r")), httpWebRequest.IfModifiedSince); Assert.AreEqual(DateTime.Parse(date.ToString("r")), DateTime.Parse(httpWebRequest.Headers["Expires"])); Assert.AreEqual("bytes=100-200", httpWebRequest.Headers["Range"]); Assert.AreEqual("bytes 100-300/*", httpWebRequest.Headers["Content-Range"]); Assert.AreEqual("TestValue", httpWebRequest.Headers["NonStandardHeader"]); var sourceStream = new MemoryStream(Encoding.UTF8.GetBytes("Test_Content")); var length = sourceStream.Length; var destinationStream = new MemoryStream(); request.WriteToRequestBody(destinationStream, sourceStream, null, 1024); var sourceContent = Encoding.UTF8.GetBytes("Test_Content"); destinationStream = new MemoryStream(); request.WriteToRequestBody(destinationStream, sourceContent, null); }
/// <summary> /// Generates a web request to return a listing of all blobs in the container. /// </summary> /// <param name="uri">A <see cref="System.Uri"/> specifying the absolute URI to the container.</param> /// <param name="timeout">An integer specifying the server timeout interval.</param> /// <param name="listingContext">A <see cref="ListingContext"/> object.</param> /// <param name="useVersionHeader">A boolean value indicating whether to set the <i>x-ms-version</i> HTTP header.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param> /// <returns>A <see cref="System.Net.HttpWebRequest"/> object.</returns> public static HttpWebRequest ListBlobs(Uri uri, int?timeout, BlobListingContext listingContext, bool useVersionHeader, OperationContext operationContext) { UriQueryBuilder builder = ContainerHttpWebRequestFactory.GetContainerUriQueryBuilder(); builder.Add(Constants.QueryConstants.Component, "list"); if (listingContext != null) { if (listingContext.Prefix != null) { builder.Add("prefix", listingContext.Prefix); } if (listingContext.Delimiter != null) { builder.Add("delimiter", listingContext.Delimiter); } if (listingContext.Marker != null) { builder.Add("marker", listingContext.Marker); } if (listingContext.MaxResults.HasValue) { builder.Add("maxresults", listingContext.MaxResults.ToString()); } if (listingContext.Details != BlobListingDetails.None) { StringBuilder sb = new StringBuilder(); bool started = false; if ((listingContext.Details & BlobListingDetails.Snapshots) == BlobListingDetails.Snapshots) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("snapshots"); } if ((listingContext.Details & BlobListingDetails.UncommittedBlobs) == BlobListingDetails.UncommittedBlobs) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("uncommittedblobs"); } if ((listingContext.Details & BlobListingDetails.Metadata) == BlobListingDetails.Metadata) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("metadata"); } if ((listingContext.Details & BlobListingDetails.Copy) == BlobListingDetails.Copy) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("copy"); } builder.Add("include", sb.ToString()); } } HttpWebRequest request = HttpWebRequestFactory.CreateWebRequest(WebRequestMethods.Http.Get, uri, timeout, builder, useVersionHeader, operationContext); return(request); }
/// <summary> /// Generates a web request to set user-defined metadata for the queue. /// </summary> /// <param name="uri">The absolute URI to the queue.</param> /// <param name="timeout">The server timeout interval.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object for tracking the current operation.</param> /// <returns>A web request to use to perform the operation.</returns> public static HttpWebRequest SetMetadata(Uri uri, int?timeout, OperationContext operationContext) { HttpWebRequest request = HttpWebRequestFactory.SetMetadata(uri, timeout, null, operationContext); return(request); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddSession(options => { options.IdleTimeout = TimeSpan.FromMinutes(15); }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddDbContext <EntityFrameWorkMagicContext>(options => options.UseSqlServer(Configuration.GetConnectionString("EntityFrameWorkMagicContext"))); // DI var connectionString = Environment.GetEnvironmentVariable("SQL_CONNECTION") ?? Configuration.GetConnectionString("ConnMsSQL"); var projectRepository = new ProjectRepository(connectionString); var componentRepository = new ComponentRepository(connectionString); var ossIndexRepository = new OssIndexRepository(connectionString); var ossIndexVulnerabilitiesRepository = new OssIndexVulnerabilitiesRepository(connectionString); var reportRepository = new ReportRepository(connectionString); var reportLinesRepository = new ReportLinesRepository(connectionString); var packageTypeRepository = new PackageTypeRepository(); var httpWebRequestFactory = new HttpWebRequestFactory(); var coordinatesService = new CoordinatesService(); var jsonConvertService = new JsonConvertService(); var ossReportService = new OssReportService( reportRepository, componentRepository, ossIndexRepository, reportLinesRepository, coordinatesService, httpWebRequestFactory, jsonConvertService, ossIndexVulnerabilitiesRepository); services.AddTransient <IProjectRepository>(s => projectRepository); services.AddTransient <IComponentRepository>(s => componentRepository); services.AddTransient <IOssIndexRepository>(s => ossIndexRepository); services.AddTransient <IOssIndexVulnerabilitiesRepository>(s => ossIndexVulnerabilitiesRepository); services.AddTransient <IReportRepository>(s => reportRepository); services.AddTransient <IReportLinesRepository>(s => reportLinesRepository); services.AddTransient <IPackageTypeRepository>(s => packageTypeRepository); services.AddSingleton <IJsonConvertService>(jsonConvertService); services.AddSingleton <ICoordinatesService>(coordinatesService); services.AddSingleton <ISelectListItemService>(new SelectListItemService(projectRepository, packageTypeRepository)); services.AddSingleton <IScoreService>(new ScoreService(reportRepository, reportLinesRepository, ossIndexRepository, ossIndexVulnerabilitiesRepository)); services.AddSingleton <IScoreClassService>(new ScoreClassService()); services.AddSingleton <IBreadcrumbReportService>(new BreadcrumbReportService()); services.AddSingleton <IOssReportService>(ossReportService); services.AddSingleton <IOssIndexStatusService>(new OssIndexStatusService( reportRepository, reportLinesRepository, ossIndexRepository)); services.AddSingleton <IApiCallerService>(new ApiCallerService( ossIndexRepository, ossReportService)); services.AddSingleton <ICoordinatePartsFactory>(new CoordinatePartsFactory()); services.AddSingleton <IHttpWebRequestFactory>(httpWebRequestFactory); }
internal RemoteSettingsInitializer FillWithDefaults() { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown if (!UsePathPrefix.HasValue) { UsePathPrefix = true; } if (RemoteSettingsFileName == null) { RemoteSettingsFileName = "Default.json"; } if (KeyValueStorage == null) { KeyValueStorage = new DefaultRegistryKeyValueStorage((IRegistryTools3)(object)new RegistryTools()); } if (FilterProvider == null) { FilterProvider = new DefaultRemoteSettingsFilterProvider(TelemetryService.DefaultSession); } if (RemoteSettingsLogger == null) { RemoteSettingsLogger = new RemoteSettingsLogger(FilterProvider, RemoteSettingsStorageHandlerFactory.BuildIsLoggingEnabled(KeyValueStorage, UsePathPrefix.HasValue && UsePathPrefix.Value)()); } if (ScopeParserFactory == null) { ScopeParserFactory = new ScopeParserFactory(this); } RemoteSettingsStorageHandlerFactory remoteSettingsStorageHandlerFactory = new RemoteSettingsStorageHandlerFactory(RemoteSettingsLogger); if (VersionedRemoteSettingsStorageHandler == null) { VersionedRemoteSettingsStorageHandler = remoteSettingsStorageHandlerFactory.BuildVersioned(KeyValueStorage, UsePathPrefix.HasValue && UsePathPrefix.Value, RemoteSettingsFileName, ScopeParserFactory); } if (CacheableRemoteSettingsStorageHandler == null) { CacheableRemoteSettingsStorageHandler = remoteSettingsStorageHandlerFactory.Build(KeyValueStorage, UsePathPrefix.HasValue && UsePathPrefix.Value, FilterProvider, ScopeParserFactory); } if (LocalTestRemoteSettingsStorageHandler == null) { LocalTestRemoteSettingsStorageHandler = remoteSettingsStorageHandlerFactory.Build(KeyValueStorage, UsePathPrefix.HasValue && UsePathPrefix.Value, "LocalTest", ScopeParserFactory); } if (LiveRemoteSettingsStorageHandlerFactory == null) { LiveRemoteSettingsStorageHandlerFactory = (() => remoteSettingsStorageHandlerFactory.Build(new MemoryKeyValueStorage(), false, string.Empty, ScopeParserFactory)); } if (NonScopedRemoteSettingsStorageHandler == null && NonScopedSettingsKeyValueStorage != null) { NonScopedRemoteSettingsStorageHandler = remoteSettingsStorageHandlerFactory.Build(NonScopedSettingsKeyValueStorage, false, string.Empty, ScopeParserFactory); } if (IsUpdatedDisabled == null) { IsUpdatedDisabled = RemoteSettingsStorageHandlerFactory.BuildIsUpdateDisabled(KeyValueStorage, UsePathPrefix.HasValue && UsePathPrefix.Value); } if (RemoteFileReaderFactory == null) { RemoteFileReaderFactory = new RemoteSettingsRemoteFileReaderFactory(RemoteSettingsFileName); } if (RemoteSettingsValidator == null) { RemoteSettingsValidator = new RemoteSettingsValidator(new CycleDetection(), VersionedRemoteSettingsStorageHandler); } if (RemoteSettingsParser == null) { RemoteSettingsParser = new RemoteSettingsParser(RemoteSettingsValidator); } if (TargetedNotificationsParser == null) { TargetedNotificationsParser = new TargetedNotificationsParser(); } if (ExperimentationService == null) { ExperimentationService = Coding4Fun.VisualStudio.Experimentation.ExperimentationService.Default; } if (ExperimentationService == null) { ExperimentationService = Coding4Fun.VisualStudio.Experimentation.ExperimentationService.Default; } if (TelemetryNotificationService == null) { TelemetryNotificationService = Coding4Fun.VisualStudio.Telemetry.Notification.TelemetryNotificationService.Default; } if (Telemetry == null) { Telemetry = new DefaultRemoteSettingsTelemetry(TelemetryService.DefaultSession); } if (TargetedNotificationsTelemetry == null) { TargetedNotificationsTelemetry = new DefaultTargetedNotificationsTelemetry(TelemetryService.DefaultSession); } if (TargetedNotificationsCacheStorage == null) { TargetedNotificationsCacheStorage = new TargetedNotificationsJsonStorageProvider(this); } if (HttpWebRequestFactory == null) { HttpWebRequestFactory = new HttpWebRequestFactory(); } if (ScopeFilterProviders == null) { new ProcessInformationProvider(); ScopeFilterProviders = new List <IScopeFilterProvider> { new FlightScopeFilterProvider(ExperimentationService), new InternalScopeFilterProvider(TelemetryService.DefaultSession), new VersionScopeFilterProvider(FilterProvider), new ExeNameScopeFilterProvider(FilterProvider), new ScopeScopeFilterProvider(VersionedRemoteSettingsStorageHandler, ScopeParserFactory) }; } if (RemoteSettingsProviders == null) { RemoteSettingsProviders = new List <Func <RemoteSettingsInitializer, IRemoteSettingsProvider> > { (RemoteSettingsInitializer remoteSettingsInitializer) => new LocalTestProvider(remoteSettingsInitializer), (RemoteSettingsInitializer remoteSettingsInitializer) => new TargetedNotificationsProvider(remoteSettingsInitializer), (RemoteSettingsInitializer remoteSettingsInitializer) => new RemoteControlRemoteSettingsProvider(remoteSettingsInitializer) }; } if (LocalTestDirectories == null) { string rootPath = Path.Combine(GetLocalAppDataRoot(), "LocalTest"); LocalTestDirectories = new List <IDirectoryReader> { new DirectoryReader(rootPath, "PersistentActions", false, 0, RemoteSettingsLogger), new DirectoryReader(rootPath, "OneTimeActions", true, 10, RemoteSettingsLogger) }; } if (LocalTestParser == null) { LocalTestParser = new LocalTestParser(); } if (StableRemoteSettingsProvider == null) { StableRemoteSettingsProvider = ((RemoteSettingsInitializer remoteSettingsInitializer) => new StableRemoteSettingsProvider(remoteSettingsInitializer)); } if (StableSettingRootSubCollections == null) { StableSettingRootSubCollections = Enumerable.Empty <string>(); } return(this); }
/// <summary> /// Constructs a web request to create a new container. /// </summary> /// <param name="uri">The absolute URI to the container.</param> /// <param name="timeout">The server timeout interval.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object for tracking the current operation.</param> /// <returns>A web request to use to perform the operation.</returns> public static HttpWebRequest Create(Uri uri, int?timeout, OperationContext operationContext) { UriQueryBuilder containerBuilder = GetContainerUriQueryBuilder(); return(HttpWebRequestFactory.Create(uri, timeout, containerBuilder, operationContext)); }
public void TestHttpRequestCancellation() { IHttpRequestFactory<Stream> factory = new HttpWebRequestFactory(); var request = factory.CreateHttpRequest(new Uri(@"https://testuri")); request.Method = "PUT"; var httpWebRequest = ((HttpRequest)request).Request; Assert.AreEqual("PUT", httpWebRequest.Method); var putObjectRequest = new PutObjectRequest { BucketName = "TestBucket", Key = "TestKey", ContentBody = "Test_Content", }; var requestContext = new RequestContext(true) { ClientConfig = new AmazonS3Config { }, Marshaller = new PutObjectRequestMarshaller(), OriginalRequest = putObjectRequest, Request = new PutObjectRequestMarshaller().Marshall(putObjectRequest), Unmarshaller = new PutObjectResponseUnmarshaller(), }; request.ConfigureRequest(requestContext); var sourceStream = new MemoryStream(Encoding.UTF8.GetBytes("Test_Content")); var length = sourceStream.Length; var destinationStream = new MemoryStream(); var cts = new CancellationTokenSource(); cts.Cancel(); var token = cts.Token; requestContext.CancellationToken = token; try { request.WriteToRequestBody(destinationStream, sourceStream, null, requestContext); } catch (OperationCanceledException exception) { Assert.AreEqual(token, exception.CancellationToken); Assert.AreEqual(true, exception.CancellationToken.IsCancellationRequested); return; } Assert.Fail("An OperationCanceledException was not thrown"); }
public void TestHttpRequest() { IHttpRequestFactory <Stream> factory = new HttpWebRequestFactory(); var request = factory.CreateHttpRequest(new Uri(@"https://testuri")); Assert.IsNotNull(request); request.Method = "PUT"; var httpWebRequest = ((HttpRequest)request).Request; Assert.AreEqual("PUT", httpWebRequest.Method); var putObjectRequest = new PutObjectRequest { BucketName = "TestBucket", Key = "TestKey", ContentBody = "Test_Content", }; var proxyCreds = new System.Net.NetworkCredential("UserName", "Password"); var requestContext = new RequestContext(true) { ClientConfig = new AmazonS3Config { ConnectionLimit = 10, MaxIdleTime = 1000, ProxyCredentials = proxyCreds, ProxyHost = "proxyhost", ProxyPort = 8080, ReadWriteTimeout = TimeSpan.FromSeconds(20), Timeout = TimeSpan.FromSeconds(40), UseNagleAlgorithm = false, }, Marshaller = new PutObjectRequestMarshaller(), OriginalRequest = putObjectRequest, Request = new PutObjectRequestMarshaller().Marshall(putObjectRequest), Unmarshaller = new PutObjectResponseUnmarshaller() }; request.ConfigureRequest(requestContext); Assert.IsInstanceOfType(httpWebRequest.Proxy, typeof(WebProxy)); Assert.AreEqual(new Uri("http://proxyhost:8080"), ((WebProxy)httpWebRequest.Proxy).Address); Assert.AreEqual(proxyCreds, httpWebRequest.Proxy.Credentials); Assert.AreEqual(40000, httpWebRequest.Timeout); Assert.AreEqual(20000, httpWebRequest.ReadWriteTimeout); Assert.AreEqual(1000, httpWebRequest.ServicePoint.MaxIdleTime); Assert.AreEqual(false, httpWebRequest.ServicePoint.UseNagleAlgorithm); var date = DateTime.Now.ToUniversalTime(); request.SetRequestHeaders(new Dictionary <string, string> { { "Accept", "text/plain" }, //{"Connection","Keep-Alive"}, { "Content-Type", "application/json" }, { "Content-Length", "100" }, //{"Expect","100-continue"}, { "User-Agent", "awssdk" }, { "Date", date.ToString("r") }, //{"Host","s3.amazonaws.com"}, { "Range", "bytes=100-200" }, { "Content-Range", "bytes 100-300/*" }, { "If-Modified-Since", date.ToString("r") }, { "Expires", date.ToString("r") }, { "NonStandardHeader", "TestValue" }, }); Assert.AreEqual("text/plain", httpWebRequest.Accept); Assert.AreEqual("application/json", httpWebRequest.ContentType); Assert.AreEqual(100, httpWebRequest.ContentLength); Assert.AreEqual("awssdk", httpWebRequest.UserAgent); Assert.AreEqual(DateTime.Parse(date.ToString("r")), httpWebRequest.Date); Assert.AreEqual("testuri", httpWebRequest.Host); Assert.AreEqual(DateTime.Parse(date.ToString("r")), httpWebRequest.IfModifiedSince); Assert.AreEqual(DateTime.Parse(date.ToString("r")), DateTime.Parse(httpWebRequest.Headers["Expires"])); Assert.AreEqual("bytes=100-200", httpWebRequest.Headers["Range"]); Assert.AreEqual("bytes 100-300/*", httpWebRequest.Headers["Content-Range"]); Assert.AreEqual("TestValue", httpWebRequest.Headers["NonStandardHeader"]); var sourceStream = new MemoryStream(Encoding.UTF8.GetBytes("Test_Content")); var length = sourceStream.Length; var destinationStream = new MemoryStream(); request.WriteToRequestBody(destinationStream, sourceStream, null, requestContext); var sourceContent = Encoding.UTF8.GetBytes("Test_Content"); destinationStream = new MemoryStream(); request.WriteToRequestBody(destinationStream, sourceContent, null); }
public void Init() { _factory = new HttpWebRequestFactory(); }
/// <summary> /// Constructs a web request to set the ACL for a table. /// </summary> /// <param name="uri">The absolute URI to the table.</param> /// <param name="builder">An object of type <see cref="UriQueryBuilder"/>, containing additional parameters to add to the URI query string.</param> /// <param name="timeout">The server timeout interval.</param> /// <param name="operationContext">An <see cref="OperationContext" /> object for tracking the current operation.</param> /// <returns> /// A web request to use to perform the operation. /// </returns> public static HttpWebRequest SetAcl(Uri uri, UriQueryBuilder builder, int?timeout, OperationContext operationContext) { return(HttpWebRequestFactory.SetAcl(uri, builder, timeout, operationContext)); }
/// <summary> /// Creates a web request to get the properties of the Blob service account. /// </summary> /// <param name="uri">A <see cref="System.Uri"/> specifying the Blob service endpoint.</param> /// <param name="builder">A <see cref="UriQueryBuilder"/> object specifying additional parameters to add to the URI query string.</param> /// <param name="timeout">The server timeout interval, in seconds.</param> /// <param name="useVersionHeader">A boolean value indicating whether to set the <i>x-ms-version</i> HTTP header.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param> /// <returns>A <see cref="System.Net.HttpWebRequest"/> object.</returns> internal static HttpWebRequest GetAccountProperties(Uri uri, UriQueryBuilder builder, int?timeout, bool useVersionHeader, OperationContext operationContext) { return(HttpWebRequestFactory.GetAccountProperties(uri, builder, timeout, useVersionHeader, operationContext)); }
private void BuildRuntimePipeline() { #if BCL var httpRequestFactory = new HttpWebRequestFactory(new AmazonSecurityProtocolManager()); var httpHandler = new HttpHandler <Stream>(httpRequestFactory, this); #elif UNITY IHttpRequestFactory <string> httpRequestFactory = null; HttpHandler <string> httpHandler = null; if (AWSConfigs.HttpClient == AWSConfigs.HttpClientOption.UnityWWW) { httpRequestFactory = new UnityWwwRequestFactory(); httpHandler = new HttpHandler <string>(httpRequestFactory, this); } else { httpRequestFactory = new UnityWebRequestFactory(); httpHandler = new HttpHandler <string>(httpRequestFactory, this); } #else var httpRequestFactory = new HttpRequestMessageFactory(this.Config); var httpHandler = new HttpHandler <System.Net.Http.HttpContent>(httpRequestFactory, this); #endif var preMarshallHandler = new CallbackHandler(); preMarshallHandler.OnPreInvoke = this.ProcessPreRequestHandlers; var postMarshallHandler = new CallbackHandler(); postMarshallHandler.OnPreInvoke = this.ProcessRequestHandlers; var postUnmarshallHandler = new CallbackHandler(); postUnmarshallHandler.OnPostInvoke = this.ProcessResponseHandlers; var errorCallbackHandler = new ErrorCallbackHandler(); errorCallbackHandler.OnError = this.ProcessExceptionHandlers; // Build default runtime pipeline. this.RuntimePipeline = new RuntimePipeline(new List <IPipelineHandler> { httpHandler, new Unmarshaller(this.SupportResponseLogging), new ErrorHandler(_logger), postUnmarshallHandler, new Signer(), //EndpointDiscoveryResolver must come after CredentialsRetriever, RetryHander, and EndpointResolver as it depends on //credentials, retrying of requests for 421 web exceptions, and the current set regional endpoint. new EndpointDiscoveryHandler(), new CredentialsRetriever(this.Credentials), new RetryHandler(new DefaultRetryPolicy(this.Config)), postMarshallHandler, new EndpointResolver(), new Marshaller(), preMarshallHandler, errorCallbackHandler, new MetricsHandler() #if UNITY , new ThreadPoolExecutionHandler(10) //remove the hardcoded to unity config #endif }, _logger ); #if BCL || NETSTANDARD if (DeterminedCSMConfiguration.Instance.CSMConfiguration.Enabled && !string.IsNullOrEmpty(ServiceMetadata.ServiceId)) { this.RuntimePipeline.AddHandlerBefore <ErrorHandler>(new CSMCallAttemptHandler()); this.RuntimePipeline.AddHandlerBefore <MetricsHandler>(new CSMCallEventHandler()); } #endif CustomizeRuntimePipeline(this.RuntimePipeline); // Apply global pipeline customizations RuntimePipelineCustomizerRegistry.Instance.ApplyCustomizations(this.GetType(), this.RuntimePipeline); }
/// <summary> /// Constructs a web request to create a new share. /// </summary> /// <param name="uri">The absolute URI to the share.</param> /// <param name="timeout">The server timeout interval.</param> /// <param name="useVersionHeader">A flag indicating whether to set the x-ms-version HTTP header.</param> /// <param name="operationContext">An <see cref="OperationContext" /> object for tracking the current operation.</param> /// <returns>A web request to use to perform the operation.</returns> public static HttpWebRequest Create(Uri uri, int?timeout, bool useVersionHeader, OperationContext operationContext) { UriQueryBuilder shareBuilder = GetShareUriQueryBuilder(); return(HttpWebRequestFactory.Create(uri, timeout, shareBuilder, useVersionHeader, operationContext)); }
private void BuildRuntimePipeline() { #if BCL || BCL45 var httpRequestFactory = new HttpWebRequestFactory(); var httpHandler = new HttpHandler <Stream>(httpRequestFactory, this); #elif UNITY IHttpRequestFactory <string> httpRequestFactory = null; HttpHandler <string> httpHandler = null; if (AWSConfigs.HttpClient == AWSConfigs.HttpClientOption.UnityWWW) { httpRequestFactory = new UnityWwwRequestFactory(); httpHandler = new HttpHandler <string>(httpRequestFactory, this); } else { httpRequestFactory = new UnityWebRequestFactory(); httpHandler = new HttpHandler <string>(httpRequestFactory, this); } #else var httpRequestFactory = new HttpRequestMessageFactory(this.Config); var httpHandler = new HttpHandler <System.Net.Http.HttpContent>(httpRequestFactory, this); #endif var preMarshallHandler = new CallbackHandler(); preMarshallHandler.OnPreInvoke = this.ProcessPreRequestHandlers; var postMarshallHandler = new CallbackHandler(); postMarshallHandler.OnPreInvoke = this.ProcessRequestHandlers; var postUnmarshallHandler = new CallbackHandler(); postUnmarshallHandler.OnPostInvoke = this.ProcessResponseHandlers; var errorCallbackHandler = new ErrorCallbackHandler(); errorCallbackHandler.OnError = this.ProcessExceptionHandlers; // Build default runtime pipeline. this.RuntimePipeline = new RuntimePipeline(new List <IPipelineHandler> { httpHandler, new Unmarshaller(this.SupportResponseLogging), new ErrorHandler(_logger), postUnmarshallHandler, new Signer(), new CredentialsRetriever(this.Credentials), new RetryHandler(new DefaultRetryPolicy(this.Config)), postMarshallHandler, new EndpointResolver(), new Marshaller(), preMarshallHandler, errorCallbackHandler, new MetricsHandler() #if UNITY , new ThreadPoolExecutionHandler(10) //remove the hardcoded to unity config #endif }, _logger ); CustomizeRuntimePipeline(this.RuntimePipeline); // Apply global pipeline customizations RuntimePipelineCustomizerRegistry.Instance.ApplyCustomizations(this.GetType(), this.RuntimePipeline); }
/// <summary> /// Creates a web request to get the properties of the Blob service. /// </summary> /// <param name="uri">The absolute URI to the Blob service.</param> /// <param name="builder">An object of type <see cref="UriQueryBuilder"/>, containing additional parameters to add to the URI query string.</param> /// <param name="timeout">The server timeout interval, in seconds.</param> /// <param name="operationContext">An <see cref="OperationContext" /> object for tracking the current operation.</param> /// <returns> /// A web request to get the Blob service properties. /// </returns> public static HttpWebRequest GetServiceProperties(Uri uri, UriQueryBuilder builder, int?timeout, OperationContext operationContext) { return(HttpWebRequestFactory.GetServiceProperties(uri, builder, timeout, operationContext)); }
/// <summary> /// Constructs a web request to create a new queue. /// </summary> /// <param name="uri">A <see cref="System.Uri"/> specifying the absolute URI to the queue.</param> /// <param name="timeout">An integer specifying the server timeout interval.</param> /// <param name="useVersionHeader">A boolean value indicating whether to set the <i>x-ms-version</i> HTTP header.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param> /// <returns>A <see cref="System.Net.HttpWebRequest"/> object.</returns> public static HttpWebRequest Create(Uri uri, int?timeout, bool useVersionHeader, OperationContext operationContext) { return(HttpWebRequestFactory.Create(uri, timeout, null, useVersionHeader, operationContext)); }
/// <summary> /// Creates a web request to set the properties of the File service. /// </summary> /// <param name="uri">A <see cref="System.Uri"/> specifying the File service endpoint.</param> /// <param name="builder">A <see cref="UriQueryBuilder"/> object specifying additional parameters to add to the URI query string.</param> /// <param name="timeout">The server timeout interval, in seconds.</param> /// <param name="useVersionHeader">A boolean value indicating whether to set the <i>x-ms-version</i> HTTP header.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param> /// <returns>A <see cref="System.Net.HttpWebRequest"/> object.</returns> public static HttpWebRequest SetServiceProperties(Uri uri, UriQueryBuilder builder, int?timeout, bool useVersionHeader, OperationContext operationContext) { return(HttpWebRequestFactory.SetServiceProperties(uri, builder, timeout, useVersionHeader, operationContext)); }
/// <summary> /// Constructs a web request to clear all messages in the queue. /// </summary> /// <param name="uri">A <see cref="System.Uri"/> specifying the absolute URI to the queue.</param> /// <param name="timeout">An integer specifying the server timeout interval.</param> /// <param name="useVersionHeader">A boolean value indicating whether to set the <i>x-ms-version</i> HTTP header.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param> /// <returns>A <see cref="System.Net.HttpWebRequest"/> object.</returns> public static HttpWebRequest ClearMessages(Uri uri, int?timeout, bool useVersionHeader, OperationContext operationContext) { HttpWebRequest request = HttpWebRequestFactory.Delete(uri, null, timeout, useVersionHeader, operationContext); return(request); }
/// <summary> /// Adds user-defined metadata to the request as one or more name-value pairs. /// </summary> /// <param name="request">The web request.</param> /// <param name="metadata">The user-defined metadata.</param> public static void AddMetadata(HttpWebRequest request, IDictionary <string, string> metadata) { HttpWebRequestFactory.AddMetadata(request, metadata); }
/// <summary> /// Generates a web request to return the user-defined metadata for this queue. /// </summary> /// <param name="uri">A <see cref="System.Uri"/> specifying the absolute URI to the queue.</param> /// <param name="timeout">An integer specifying the server timeout interval.</param> /// <param name="useVersionHeader">A boolean value indicating whether to set the <i>x-ms-version</i> HTTP header.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param> /// <returns>A <see cref="System.Net.HttpWebRequest"/> object.</returns> public static HttpWebRequest GetMetadata(Uri uri, int?timeout, bool useVersionHeader, OperationContext operationContext) { HttpWebRequest request = HttpWebRequestFactory.GetMetadata(uri, timeout, null, useVersionHeader, operationContext); return(request); }
/// <summary> /// Constructs a web request to return the ACL for a queue. /// </summary> /// <param name="uri">The absolute URI to the queue.</param> /// <param name="timeout">The server timeout interval.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object for tracking the current operation.</param> /// <returns>A web request to use to perform the operation.</returns> public static HttpWebRequest GetAcl(Uri uri, int?timeout, OperationContext operationContext) { HttpWebRequest request = HttpWebRequestFactory.GetAcl(uri, null, timeout, operationContext); return(request); }
/// <summary> /// Constructs a web request to set the ACL for a queue. /// </summary> /// <param name="uri">A <see cref="System.Uri"/> specifying the absolute URI to the queue.</param> /// <param name="timeout">An integer specifying the server timeout interval.</param> /// <param name="useVersionHeader">A boolean value indicating whether to set the <i>x-ms-version</i> HTTP header.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param> /// <returns>A <see cref="System.Net.HttpWebRequest"/> object.</returns> public static HttpWebRequest SetAcl(Uri uri, int?timeout, bool useVersionHeader, OperationContext operationContext) { HttpWebRequest request = HttpWebRequestFactory.SetAcl(uri, null, timeout, useVersionHeader, operationContext); return(request); }
public DefaultMirthConnectRequestFactory(string baseUrl) { BaseUrl = baseUrl; HttpWebRequestFactory = new HttpWebRequestFactory(); }
/// <summary> /// Constructs a web request to return a listing of all shares in this storage account. /// </summary> /// <param name="uri">The absolute URI for the account.</param> /// <param name="timeout">The server timeout interval.</param> /// <param name="listingContext">A set of parameters for the listing operation.</param> /// <param name="detailsIncluded">Additional details to return with the listing.</param> /// <param name="useVersionHeader">A boolean value indicating whether to set the <i>x-ms-version</i> HTTP header.</param> /// <param name="operationContext">An <see cref="OperationContext" /> object for tracking the current operation.</param> /// <returns>A web request for the specified operation.</returns> public static HttpWebRequest List(Uri uri, int?timeout, ListingContext listingContext, ShareListingDetails detailsIncluded, bool useVersionHeader, OperationContext operationContext) { UriQueryBuilder builder = new UriQueryBuilder(); builder.Add(Constants.QueryConstants.Component, "list"); if (listingContext != null) { if (listingContext.Prefix != null) { builder.Add("prefix", listingContext.Prefix); } if (listingContext.Marker != null) { builder.Add("marker", listingContext.Marker); } if (listingContext.MaxResults.HasValue) { builder.Add("maxresults", listingContext.MaxResults.ToString()); } } if (detailsIncluded != ShareListingDetails.None) { StringBuilder sb = new StringBuilder(); bool started = false; if ((detailsIncluded & ShareListingDetails.Metadata) == ShareListingDetails.Metadata) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("metadata"); } if ((detailsIncluded & ShareListingDetails.Snapshots) == ShareListingDetails.Snapshots) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("snapshots"); } builder.Add("include", sb.ToString()); } HttpWebRequest request = HttpWebRequestFactory.CreateWebRequest(WebRequestMethods.Http.Get, uri, timeout, builder, useVersionHeader, operationContext); return(request); }