/// <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}"); } }
private void SetHeaders(HttpListenerContext context, string localPath, string utcFileDateString) { var fileExtension = Path.GetExtension(localPath); if (MimeTypes.ContainsKey(fileExtension)) { context.Response.ContentType = MimeTypes[fileExtension]; } context.Response.AddHeader(Headers.CacheControl, DefaultHeaders.ContainsKey(Headers.CacheControl) ? DefaultHeaders[Headers.CacheControl] : "private"); context.Response.AddHeader(Headers.Pragma, DefaultHeaders.ContainsKey(Headers.Pragma) ? DefaultHeaders[Headers.Pragma] : string.Empty); context.Response.AddHeader(Headers.Expires, DefaultHeaders.ContainsKey(Headers.Expires) ? DefaultHeaders[Headers.Expires] : string.Empty); context.Response.AddHeader(Headers.LastModified, utcFileDateString); context.Response.AddHeader(Headers.AcceptRanges, "bytes"); }
/// <summary> /// Deauthenticates this instance, disposing of the Auth token. /// </summary> /// <returns></returns> public async Task Deauthenticate() { if (DefaultHeaders.ContainsKey(HeaderAuthorization)) { DefaultHeaders.Remove(HeaderAuthorization); } }
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> /// Sets the default cache headers. /// </summary> /// <param name="response">The response.</param> protected void SetDefaultCacheHeaders(IHttpResponse response) { response.AddHeader(Headers.CacheControl, DefaultHeaders.GetValueOrDefault(Headers.CacheControl, "private")); response.AddHeader(Headers.Pragma, DefaultHeaders.GetValueOrDefault(Headers.Pragma, string.Empty)); response.AddHeader(Headers.Expires, DefaultHeaders.GetValueOrDefault(Headers.Expires, string.Empty)); }
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> /// Creates new instance of <see cref="DefaultHeadersTransform"/>. /// </summary> /// <param name="defaultHeaders">A set of default headers which will be appended to requests on transform.</param> public DefaultHeadersTransform([CanBeNull] IEnumerable <Header> defaultHeaders = null) { DefaultHeaders = Headers.Empty; if (defaultHeaders == null) { return; } foreach (var header in defaultHeaders) { DefaultHeaders = DefaultHeaders.Set(header.Name, header.Value); } }
/// <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); } }
private void SetStatusCode304(HttpListenerContext context) { context.Response.AddHeader(Headers.CacheControl, DefaultHeaders.ContainsKey(Headers.CacheControl) ? DefaultHeaders[Headers.CacheControl] : "private"); context.Response.AddHeader(Headers.Pragma, DefaultHeaders.ContainsKey(Headers.Pragma) ? DefaultHeaders[Headers.Pragma] : string.Empty); context.Response.AddHeader(Headers.Expires, DefaultHeaders.ContainsKey(Headers.Expires) ? DefaultHeaders[Headers.Expires] : string.Empty); context.Response.ContentType = string.Empty; context.Response.StatusCode = 304; }
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://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); } }
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); } }
protected DefaultHttpHeaders(DefaultHeaders <AsciiString, ICharSequence> headers) { this.headers = headers; }
public void AfterEach() { DefaultHeaders.Clear(); }