/// <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); } }
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; }