public Configuration( IDictionary<string, string> defaultHeaders, IDictionary<string, string> apiKey, IDictionary<string, string> apiKeyPrefix, string basePath = "http://petstore.swagger.io/v2") : this() { if (string.IsNullOrWhiteSpace(basePath)) throw new ArgumentException("The provided basePath is invalid.", "basePath"); if (defaultHeaders == null) throw new ArgumentNullException("defaultHeaders"); if (apiKey == null) throw new ArgumentNullException("apiKey"); if (apiKeyPrefix == null) throw new ArgumentNullException("apiKeyPrefix"); BasePath = basePath; foreach (var keyValuePair in defaultHeaders) { DefaultHeaders.Add(keyValuePair); } foreach (var keyValuePair in apiKey) { ApiKey.Add(keyValuePair); } foreach (var keyValuePair in apiKeyPrefix) { ApiKeyPrefix.Add(keyValuePair); } }
/// <summary> /// Authenticates the using the specified <see cref="authToken" />. /// </summary> /// <param name="authToken">The authentication token.</param> /// <returns></returns> public async Task Authenticate(string authToken) { if (!DefaultHeaders.ContainsKey(HeaderAuthorization)) { DefaultHeaders.Add(HeaderAuthorization, $"JWT {authToken}"); } }
public void can_set_default_values_for_headers() { Get("/info").Body.ShouldNotContain("Header: CONTENT_TYPE = application/json"); DefaultHeaders.Add("Content-Type", "application/json"); Get("/info").Body.ShouldContain("Header: CONTENT_TYPE = application/json"); DefaultHeaders.Remove("Content-Type"); Get("/info").Body.ShouldNotContain("Header: CONTENT_TYPE = application/json"); }
public void can_override_default_values_for_headers() { DefaultHeaders.Add("FOO", "bar"); DefaultHeaders.Add("HI", "there"); Get("/info").Body.ShouldContain("Header: HTTP_FOO = bar"); Get("/info").Body.ShouldContain("Header: HTTP_HI = there"); Get("/info").Body.ShouldNotContain("Header: HTTP_FOO = overriden"); // HI's default value is still passed along but FOO get overriden Get("/info", new { Headers = new { FOO = "overriden!" } }).Body.ShouldContain("Header: HTTP_FOO = overriden!"); Get("/info", new { Headers = new { FOO = "overriden!" } }).Body.ShouldContain("Header: HTTP_HI = there"); }
/// <summary> /// Initializes a new instance of the <see cref="InMemoryFileSystemModule" /> class. /// </summary> /// <param name="headers">The headers to set in every request.</param> /// <exception cref="System.ArgumentException">Path ' + fileSystemPath + ' does not exist.</exception> public InMemoryFileSystemModule(Dictionary <string, string> headers = null) { RamCache = MemoryCache.Default; if (headers != null) { foreach (var header in headers) { DefaultHeaders.Add(header.Key, header.Value); } } AddHandler(ModuleMap.AnyPath, HttpVerbs.Head, (context, ct) => HandleGet(context, ct, false)); AddHandler(ModuleMap.AnyPath, HttpVerbs.Get, (context, ct) => HandleGet(context, ct)); }
/// <summary> /// Initializes a new instance of the <see cref="StaticFilesModule" /> class. /// </summary> /// <param name="fileSystemPath">The file system path.</param> /// <param name="headers">The headers to set in every request.</param> /// <param name="additionalPaths">The additional paths.</param> /// <exception cref="System.ArgumentException">Path ' + fileSystemPath + ' does not exist.</exception> public StaticFilesModule( string fileSystemPath, Dictionary <string, string> headers = null, Dictionary <string, string> additionalPaths = null) { if (Directory.Exists(fileSystemPath) == false) { throw new ArgumentException($"Path '{fileSystemPath}' does not exist."); } FileSystemPath = Path.GetFullPath(fileSystemPath); UseGzip = true; #if DEBUG // When debugging, disable RamCache UseRamCache = false; #else // Otherwise, enable it by default this.UseRamCache = true; #endif RamCache = new ConcurrentDictionary <string, RamCacheEntry>(Strings.StaticFileStringComparer); MaxRamCacheFileSize = 250 * 1024; DefaultDocument = DefaultDocumentName; // Populate the default MIME types foreach (var kvp in Constants.MimeTypes.DefaultMimeTypes) { m_MimeTypes.Add(kvp.Key, kvp.Value); } if (headers != null) { foreach (var header in headers) { DefaultHeaders.Add(header.Key, header.Value); } } if (additionalPaths != null) { foreach (var path in additionalPaths.Where(path => path.Key != "/")) { RegisterVirtualPath(path.Key, path.Value); } } AddHandler(ModuleMap.AnyPath, HttpVerbs.Head, (context, ct) => HandleGet(context, ct, false)); AddHandler(ModuleMap.AnyPath, HttpVerbs.Get, (context, ct) => HandleGet(context, ct)); }
public Configuration( IDictionary <string, string> defaultHeaders, string basePath = BASE_PATH) : this() { if (string.IsNullOrWhiteSpace(basePath)) { throw new ArgumentException("The provided basePath is invalid.", "basePath"); } if (defaultHeaders == null) { throw new ArgumentNullException("defaultHeaders"); } BasePath = basePath; foreach (var keyValuePair in defaultHeaders) { DefaultHeaders.Add(keyValuePair); } }
public void can_set_default_values_for_headers_globally() { Get("/info").Body.ShouldNotContain("Header: CONTENT_TYPE = application/json"); Get("/info", new { Headers = new { ContentType = "application/foo" } }).Body.ShouldContain("Header: CONTENT_TYPE = application/foo"); Get("/info", new { Headers = new { ContentType = "application/foo" } }).Body.ShouldNotContain("Header: CONTENT_TYPE = application/json"); // global Requestor.Global.DefaultHeaders.Add("Content-Type", "application/json"); Get("/info").Body.ShouldContain("Header: CONTENT_TYPE = application/json"); Get("/info").Body.ShouldNotContain("Header: CONTENT_TYPE = application/xml"); Get("/info", new { Headers = new { ContentType = "application/foo" } }).Body.ShouldContain("Header: CONTENT_TYPE = application/foo"); Get("/info", new { Headers = new { ContentType = "application/foo" } }).Body.ShouldNotContain("Header: CONTENT_TYPE = application/json"); // override via instance DefaultHeaders.Add("Content-Type", "application/xml"); Get("/info").Body.ShouldNotContain("Header: CONTENT_TYPE = application/json"); Get("/info").Body.ShouldContain("Header: CONTENT_TYPE = application/xml"); Get("/info", new { Headers = new { ContentType = "application/foo" } }).Body.ShouldContain("Header: CONTENT_TYPE = application/foo"); Get("/info", new { Headers = new { ContentType = "application/foo" } }).Body.ShouldNotContain("Header: CONTENT_TYPE = application/json"); Get("/info", new { Headers = new { ContentType = "application/foo" } }).Body.ShouldNotContain("Header: CONTENT_TYPE = application/xml"); }
public Configuration( IDictionary <string, string> defaultHeaders, IDictionary <string, string> apiKey, IDictionary <string, string> apiKeyPrefix, string basePath = "https://virtserver.swaggerhub.com/VNGRealisatie/api/reisdocumenten") : this() { if (string.IsNullOrWhiteSpace(basePath)) { throw new ArgumentException("The provided basePath is invalid.", "basePath"); } if (defaultHeaders == null) { throw new ArgumentNullException("defaultHeaders"); } if (apiKey == null) { throw new ArgumentNullException("apiKey"); } if (apiKeyPrefix == null) { throw new ArgumentNullException("apiKeyPrefix"); } BasePath = basePath; foreach (var keyValuePair in defaultHeaders) { DefaultHeaders.Add(keyValuePair); } foreach (var keyValuePair in apiKey) { ApiKey.Add(keyValuePair); } foreach (var keyValuePair in apiKeyPrefix) { ApiKeyPrefix.Add(keyValuePair); } }
public Configuration( IDictionary <string, string> defaultHeaders, IDictionary <string, string> apiKey, IDictionary <string, string> apiKeyPrefix, string basePath = "http://healthsuite.allocatesoftware.com/api/booking/v1") : this() { if (string.IsNullOrWhiteSpace(basePath)) { throw new ArgumentException("The provided basePath is invalid.", "basePath"); } if (defaultHeaders == null) { throw new ArgumentNullException("defaultHeaders"); } if (apiKey == null) { throw new ArgumentNullException("apiKey"); } if (apiKeyPrefix == null) { throw new ArgumentNullException("apiKeyPrefix"); } BasePath = basePath; foreach (var keyValuePair in defaultHeaders) { DefaultHeaders.Add(keyValuePair); } foreach (var keyValuePair in apiKey) { ApiKey.Add(keyValuePair); } foreach (var keyValuePair in apiKeyPrefix) { ApiKeyPrefix.Add(keyValuePair); } }
public Configuration( IDictionary <string, string> defaultHeaders, IDictionary <string, string> apiKey, IDictionary <string, string> apiKeyPrefix, string basePath = "https://api.bag.acceptatie.kadaster.nl/esd/huidigebevragingen/v1") : this() { if (string.IsNullOrWhiteSpace(basePath)) { throw new ArgumentException("The provided basePath is invalid.", "basePath"); } if (defaultHeaders == null) { throw new ArgumentNullException("defaultHeaders"); } if (apiKey == null) { throw new ArgumentNullException("apiKey"); } if (apiKeyPrefix == null) { throw new ArgumentNullException("apiKeyPrefix"); } BasePath = basePath; foreach (var keyValuePair in defaultHeaders) { DefaultHeaders.Add(keyValuePair); } foreach (var keyValuePair in apiKey) { ApiKey.Add(keyValuePair); } foreach (var keyValuePair in apiKeyPrefix) { ApiKeyPrefix.Add(keyValuePair); } }
public Configuration( IDictionary <string, string> defaultHeaders, IDictionary <string, string> apiKey, IDictionary <string, string> apiKeyPrefix, string basePath = "https://connect.apptigent.com/api/utilities") : this() { if (string.IsNullOrWhiteSpace(basePath)) { throw new ArgumentException("The provided basePath is invalid.", "basePath"); } if (defaultHeaders == null) { throw new ArgumentNullException("defaultHeaders"); } if (apiKey == null) { throw new ArgumentNullException("apiKey"); } if (apiKeyPrefix == null) { throw new ArgumentNullException("apiKeyPrefix"); } BasePath = basePath; foreach (var keyValuePair in defaultHeaders) { DefaultHeaders.Add(keyValuePair); } foreach (var keyValuePair in apiKey) { ApiKey.Add(keyValuePair); } foreach (var keyValuePair in apiKeyPrefix) { ApiKeyPrefix.Add(keyValuePair); } }
public Configuration( IDictionary <string, string> defaultHeaders, IDictionary <string, string> apiKey, IDictionary <string, string> apiKeyPrefix, string basePath = "https://arqsimocfactoryservice.azurewebsites.net") : this() { if (string.IsNullOrWhiteSpace(basePath)) { throw new ArgumentException("The provided basePath is invalid.", "basePath"); } if (defaultHeaders == null) { throw new ArgumentNullException("defaultHeaders"); } if (apiKey == null) { throw new ArgumentNullException("apiKey"); } if (apiKeyPrefix == null) { throw new ArgumentNullException("apiKeyPrefix"); } BasePath = basePath; foreach (var keyValuePair in defaultHeaders) { DefaultHeaders.Add(keyValuePair); } foreach (var keyValuePair in apiKey) { ApiKey.Add(keyValuePair); } foreach (var keyValuePair in apiKeyPrefix) { ApiKeyPrefix.Add(keyValuePair); } }
public Configuration( IDictionary <string, string> defaultHeaders, IDictionary <string, string> apiKey, IDictionary <string, string> apiKeyPrefix, string basePath = "https://prod.api.appcluster01.ca-central-1.ezmax.com/rest") : this() { if (string.IsNullOrWhiteSpace(basePath)) { throw new ArgumentException("The provided basePath is invalid.", "basePath"); } if (defaultHeaders == null) { throw new ArgumentNullException("defaultHeaders"); } if (apiKey == null) { throw new ArgumentNullException("apiKey"); } if (apiKeyPrefix == null) { throw new ArgumentNullException("apiKeyPrefix"); } BasePath = basePath; foreach (var keyValuePair in defaultHeaders) { DefaultHeaders.Add(keyValuePair); } foreach (var keyValuePair in apiKey) { ApiKey.Add(keyValuePair); } foreach (var keyValuePair in apiKeyPrefix) { ApiKeyPrefix.Add(keyValuePair); } }
public Configuration( IDictionary <string, string> defaultHeaders, IDictionary <string, string> apiKey, IDictionary <string, string> apiKeyPrefix, string basePath = "https://13d16e9d-d8b1-4ef4-bc4a-ed8156b2b159.mock.pstmn.io") : this() { if (string.IsNullOrWhiteSpace(basePath)) { throw new ArgumentException("The provided basePath is invalid.", "basePath"); } if (defaultHeaders == null) { throw new ArgumentNullException("defaultHeaders"); } if (apiKey == null) { throw new ArgumentNullException("apiKey"); } if (apiKeyPrefix == null) { throw new ArgumentNullException("apiKeyPrefix"); } BasePath = basePath; foreach (var keyValuePair in defaultHeaders) { DefaultHeaders.Add(keyValuePair); } foreach (var keyValuePair in apiKey) { ApiKey.Add(keyValuePair); } foreach (var keyValuePair in apiKeyPrefix) { ApiKeyPrefix.Add(keyValuePair); } }