/// <summary> /// Initializes a new instance of the <see cref="T:Yurumi.Configurations.SendGridConfiguration"/> class. /// </summary> /// <param name="category">Category.</param> /// <param name="enableClickTracking">If set to <c>true</c> enable click tracking.</param> public SendGridConfiguration(string category, bool enableClickTracking) { var token = new Token(category, new Filters(new ClickTrack(new Settings(enableClickTracking)))); var output = JsonConvert.SerializeObject(token, new BoolConverter()); HeaderValues.Add(_header, output); }
/**************************************************************************/ private void ProcessResponseHttpHeaders(MacroscopeHttpTwoClientResponse Response) { HttpResponseMessage ResponseMessage = Response.GetResponse(); HttpResponseHeaders ResponseHeaders = ResponseMessage.Headers; HttpContentHeaders ContentHeaders = ResponseMessage.Content.Headers; /** Date HTTP Header ------------------------------------------------- **/ try { DateTimeOffset?HeaderValue = ResponseHeaders.Date; if (HeaderValue != null) { this.DateServer = MacroscopeDateTools.ParseHttpDate(DateString: HeaderValue.ToString()); } } catch (Exception ex) { this.DebugMsg(ex.Message); this.DateServer = new DateTime(); FindHttpResponseHeaderCallback Callback = delegate(IEnumerable <string> HeaderValues) { this.DateServer = MacroscopeDateTools.ParseHttpDate(DateString: HeaderValues.First().ToString()); return(true); }; if (!this.FindHttpResponseHeader(ResponseHeaders: ResponseHeaders, HeaderName: "date", Callback: Callback)) { this.FindHttpContentHeader(ContentHeaders: ContentHeaders, HeaderName: "date", Callback: Callback); } } this.DebugMsg(string.Format("this.DateServer: {0}", this.DateServer)); /** Last-Modified HTTP Header ---------------------------------------- **/ try { DateTimeOffset?HeaderValue = ContentHeaders.LastModified; if (HeaderValue != null) { this.DateModified = MacroscopeDateTools.ParseHttpDate(DateString: HeaderValue.ToString()); } } catch (Exception ex) { this.DebugMsg(ex.Message); this.DateModified = new DateTime(); FindHttpResponseHeaderCallback Callback = delegate(IEnumerable <string> HeaderValues) { this.DateModified = MacroscopeDateTools.ParseHttpDate(DateString: HeaderValues.First().ToString()); return(true); }; if (!this.FindHttpResponseHeader(ResponseHeaders: ResponseHeaders, HeaderName: "last-modified", Callback: Callback)) { this.FindHttpContentHeader(ContentHeaders: ContentHeaders, HeaderName: "last-modified", Callback: Callback); } } this.DebugMsg(string.Format("this.DateModified: {0}", this.DateModified)); return; }
private void CreateDataValues() { var mapping = _mappingInfoToExcel.OrderBy(mi => mi.ColumnIndex); var objects = _objectDataToExcel.ToList(); _dataValues = new object[_objectDataToExcel.Count(), HeaderValues.Count()]; for (int objectIndex = 0; objectIndex < objects.Count(); objectIndex++) { foreach (var mappingInfo in _mappingInfoToExcel.OrderBy(mi => mi.ColumnIndex)) { if (mappingInfo.IsDynamicRange) { var offset = 0; foreach (var value in GetDynamicValues(mappingInfo, objects[objectIndex])) { _dataValues[objectIndex, mappingInfo.ColumnIndex + offset] = value; offset++; } } else { _dataValues[objectIndex, mappingInfo.ColumnIndex] = GetValue(mappingInfo, objects[objectIndex]); } } } }
private object[,] CoyyHeadersInToResult(object[,] result) { for (int i = 0; i < HeaderValues.Count(); i++) { result[0, i] = HeaderValues[i]; } return(result); }
private void SetHeader(int index, HeaderValues title) { // Set a headers title if the index is valid if (index < this.Headers.Count) { this.Headers[index].Title = title; } }
public void CacheMatch(string value) { var headValues = new HeaderValues<EntityTag>(); headValues.AddString("\"" + value + "\""); Client.DefaultHeaders.IfNoneMatch = headValues; if (Client.DefaultHeaders.CacheControl != null) return; var cc = new CacheControl { MaxAge = new TimeSpan(0) }; Client.DefaultHeaders.CacheControl = cc; }
private static ContentCoding DetectZipFormat(HeaderValues<ContentCoding> headerValues) { if (headerValues == null || headerValues.Count == 0 || headerValues.Count > 1) { // AT: To increase our chances of parsing the content, I am assuming more than one content type resolves to identity return ContentCoding.Identity; } var contentCoding = headerValues[0]; if (contentCoding != ContentCoding.GZip && contentCoding != ContentCoding.Deflate) { throw new NotSupportedException("the stream compression format is not supported"); } return contentCoding; }
/// <summary> /// Initialize a new instance of the KryptonHeader class. /// </summary> public KryptonHeader() { // The header cannot take the focus SetStyle(ControlStyles.Selectable, false); // Set default values _style = HeaderStyle.Primary; _orientation = VisualOrientation.Top; AllowButtonSpecToolTips = false; AllowButtonSpecToolTipPriority = false; // Create storage objects Values = new HeaderValues(NeedPaintDelegate); Values.TextChanged += OnHeaderTextChanged; ButtonSpecs = new HeaderButtonSpecCollection(this); // Create the palette storage StateCommon = new PaletteHeaderRedirect(Redirector, PaletteBackStyle.HeaderPrimary, PaletteBorderStyle.HeaderPrimary, PaletteContentStyle.HeaderPrimary, NeedPaintDelegate); StateDisabled = new PaletteTripleMetric(StateCommon, NeedPaintDelegate); StateNormal = new PaletteTripleMetric(StateCommon, NeedPaintDelegate); // Our view contains background and border with content inside _drawDocker = new ViewDrawDocker(StateNormal.Back, StateNormal.Border, null); _drawContent = new ViewDrawContent(StateNormal.Content, Values, Orientation); _drawDocker.Add(_drawContent, ViewDockStyle.Fill); // Create the view manager instance ViewManager = new ViewManager(this, _drawDocker); // Create button specification collection manager _buttonManager = new ButtonSpecManagerDraw(this, Redirector, ButtonSpecs, null, new[] { _drawDocker }, new IPaletteMetric[] { StateCommon }, new[] { PaletteMetricInt.HeaderButtonEdgeInsetPrimary }, new[] { PaletteMetricPadding.HeaderButtonPaddingPrimary }, CreateToolStripRenderer, NeedPaintDelegate); // Create the manager for handling tooltips ToolTipManager = new ToolTipManager(); ToolTipManager.ShowToolTip += OnShowToolTip; ToolTipManager.CancelToolTip += OnCancelToolTip; _buttonManager.ToolTipManager = ToolTipManager; // We want to be auto sized by default, but not the property default! AutoSize = true; AutoSizeMode = AutoSizeMode.GrowAndShrink; }
private static ContentCoding DetectZipFormat(HeaderValues <ContentCoding> headerValues) { if (headerValues == null || headerValues.Count == 0 || headerValues.Count > 1) { // AT: To increase our chances of parsing the content, I am assuming more than one content type resolves to identity return(ContentCoding.Identity); } var contentCoding = headerValues[0]; if (contentCoding != ContentCoding.GZip && contentCoding != ContentCoding.Deflate) { throw new NotSupportedException("the stream compression format is not supported"); } return(contentCoding); }
/// /// <summary> /// Ctor. /// </summary> /// <param name="tag">Tag name.</param> /// <param name="enableClickTracking">Enable click tracking.</param> /// <param name="variables">Object to be serialized as a collection of variables.</param> public MailGun(string tag, bool enableClickTracking, object variables = null) { HeaderValues.Add(_headerTag, tag); HeaderValues.Add(_headerTrack, enableClickTracking ? "yes" : "no"); if (variables != null) { var output = JsonConvert.SerializeObject(variables, Formatting.None, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); HeaderValues.Add(_headerVariables, output); } }
/**************************************************************************/ private MacroscopeRedirectChainDocStruct ProcessResponseHttpHeaders(string Url, MacroscopeHttpTwoClientResponse Response) { HttpResponseMessage ResponseMessage = Response.GetResponse(); HttpResponseHeaders ResponseHeaders = ResponseMessage.Headers; HttpContentHeaders ContentHeaders = ResponseMessage.Content.Headers; MacroscopeRedirectChainDocStruct RedirectChainDocStruct = new MacroscopeRedirectChainDocStruct(); /** HTTP Status Code ------------------------------------------------- **/ RedirectChainDocStruct.StatusCode = Response.GetResponse().StatusCode; /** URL ------------------------------------------------- **/ RedirectChainDocStruct.Url = Url; /** Location HTTP Header --------------------------------------------- **/ try { Uri HeaderValue = ResponseHeaders.Location; if (HeaderValue != null) { RedirectChainDocStruct.RedirectUrl = HeaderValue.ToString(); } } catch (Exception ex) { this.DebugMsg(ex.Message); FindHttpResponseHeaderCallback Callback = delegate(IEnumerable <string> HeaderValues) { RedirectChainDocStruct.RedirectUrl = HeaderValues.First().ToString(); return(true); }; if (!this.FindHttpResponseHeader(ResponseHeaders: ResponseHeaders, HeaderName: "location", Callback: Callback)) { this.FindHttpContentHeader(ContentHeaders: ContentHeaders, HeaderName: "location", Callback: Callback); } } /** ------------------------------------------------------------------ **/ return(RedirectChainDocStruct); }
/// <summary> /// Get the value for the current line for the current key /// </summary> public string GetValue(string key) { // No header means no key-based indexing if (!Header) { throw new ArgumentException("No header expected so no keys can be used"); } // If we don't have the key, return null; if (!HeaderValues.Contains(key)) { return(null); } int index = HeaderValues.IndexOf(key); if (Line.Count() < index) { throw new ArgumentException($"Current line doesn't have index {index}"); } return(Line[index]); }
public override SelectParameterResult TryCast(BindingData bindingData) { var request = bindingData.request; var parameterRequiringValidation = bindingData.parameterRequiringValidation; var bindType = parameterRequiringValidation.ParameterType; request.GetAbsoluteUri(); if (typeof(MediaTypeHeaderValue) == bindType) { if (Content.IsNullOrWhiteSpace()) { return new SelectParameterResult { valid = true, fromBody = false, fromQuery = false, fromFile = false, key = Content, parameterInfo = parameterRequiringValidation, value = request.GetMediaType(), } } ; return(bindingData.fetchBodyParam( parameterRequiringValidation, (value) => { return new SelectParameterResult { valid = true, fromBody = false, fromQuery = false, fromFile = false, key = Content, parameterInfo = parameterRequiringValidation, value = value, }; }, (why) => { return new SelectParameterResult { fromBody = false, key = "", fromQuery = false, fromFile = false, parameterInfo = parameterRequiringValidation, valid = false, failure = why, // $"Cannot extract MediaTypeHeaderValue from non-multipart request.", }; })); } if (bindType.IsSubClassOfGeneric(typeof(IHttpHeaderValueCollection <>))) { if (bindType.GenericTypeArguments.First() == typeof(StringWithQualityHeaderValue)) { if (Content.HasBlackSpace()) { return new SelectParameterResult { key = "", fromQuery = false, fromBody = false, fromFile = false, parameterInfo = parameterRequiringValidation, valid = false, failure = "AcceptLanguage is not a content header.", } } ; var accepts = request.GetAcceptLanguage().ToArray(); var valueCast = new HeaderValues <StringWithQualityHeaderValue>(accepts); return(new SelectParameterResult { valid = true, fromBody = false, fromQuery = false, fromFile = false, key = default,
public Header_Item(int _HeaderNum, HeaderValues _Title) { this.HeaderNum = _HeaderNum; this.Title = _Title; }
void TimerElapsed(object sender, ElapsedEventArgs e) { if (!this.isBusy) { return; } if (!this.IgnoreExpiresHeader) { // Since Expires is a static guess by the server, use Expires only when the server did // not send back any Etag or LastModifiedTime, which makes conditional GET impossible if (this.etag == null && this.lastModifiedTime == null && this.expires != null && (DateTime.UtcNow < this.expires.Value.ToUniversalTime())) { return; } } this.expires = null; HttpRequestMessage request = new HttpRequestMessage("GET", this.uri); if (this.etag != null) { var ifNoneMatch = new HeaderValues<EntityTag>(); ifNoneMatch.Add(this.etag); request.Headers.IfNoneMatch = ifNoneMatch; } request.Headers.IfModifiedSince = this.lastModifiedTime; bool stopTimer = false; try { HttpResponseMessage response = null; try { response = this.HttpClient.Send(request); } catch (Exception ex) { if (!this.IgnoreSendErrors) { stopTimer = InvokeHandler(ex); } if (response != null) { response.Dispose(); } return; } using (response) { switch (response.StatusCode) { case HttpStatusCode.NotModified: // the resource has not been modified response.Dispose(); break; case HttpStatusCode.OK: // the resource has been modified. Fire the event, along with the response message this.etag = response.Headers.ETag; this.expires = response.Headers.Expires; this.lastModifiedTime = response.Headers.LastModified; try { stopTimer = InvokeHandler(response); } finally { response.Dispose(); } break; default: // this is an unexpected error. Fire the event, if errors are not to be suppressed try { if (!this.IgnoreNonOKStatusCodes) { stopTimer = InvokeHandler(response); } } finally { response.Dispose(); } break; } } } finally { if (stopTimer) { StopPolling(); } } }
void TimerElapsed(object sender, ElapsedEventArgs e) { if (!this.isBusy) { return; } if (!this.IgnoreExpiresHeader) { // Since Expires is a static guess by the server, use Expires only when the server did // not send back any Etag or LastModifiedTime, which makes conditional GET impossible if (this.etag == null && this.lastModifiedTime == null && this.expires != null && (DateTime.UtcNow < this.expires.Value.ToUniversalTime())) { return; } } this.expires = null; HttpRequestMessage request = new HttpRequestMessage("GET", this.uri); if (this.etag != null) { var ifNoneMatch = new HeaderValues <EntityTag>(); ifNoneMatch.Add(this.etag); request.Headers.IfNoneMatch = ifNoneMatch; } request.Headers.IfModifiedSince = this.lastModifiedTime; bool stopTimer = false; try { HttpResponseMessage response = null; try { response = this.HttpClient.Send(request); } catch (Exception ex) { if (!this.IgnoreSendErrors) { stopTimer = InvokeHandler(ex); } if (response != null) { response.Dispose(); } return; } using (response) { switch (response.StatusCode) { case HttpStatusCode.NotModified: // the resource has not been modified response.Dispose(); break; case HttpStatusCode.OK: // the resource has been modified. Fire the event, along with the response message this.etag = response.Headers.ETag; this.expires = response.Headers.Expires; this.lastModifiedTime = response.Headers.LastModified; try { stopTimer = InvokeHandler(response); } finally { response.Dispose(); } break; default: // this is an unexpected error. Fire the event, if errors are not to be suppressed try { if (!this.IgnoreNonOKStatusCodes) { stopTimer = InvokeHandler(response); } } finally { response.Dispose(); } break; } } } finally { if (stopTimer) { StopPolling(); } } }
/**************************************************************************/ private void ProcessResponseHttpHeaders(MacroscopeHttpTwoClientResponse Response) { HttpResponseMessage ResponseMessage = Response.GetResponse(); HttpResponseHeaders ResponseHeaders = ResponseMessage.Headers; HttpContentHeaders ContentHeaders = ResponseMessage.Content.Headers; /** Status Code ------------------------------------------------------ **/ this.SetStatusCode(ResponseMessage.StatusCode); this.SetErrorCondition(ResponseMessage.ReasonPhrase); try { switch (this.GetStatusCode()) { // 200 Range case HttpStatusCode.OK: this.SetIsNotRedirect(); break; // 300 Range case HttpStatusCode.Moved: this.SetErrorCondition(HttpStatusCode.Moved.ToString()); this.SetIsRedirect(); break; case HttpStatusCode.SeeOther: this.SetErrorCondition(HttpStatusCode.SeeOther.ToString()); this.SetIsRedirect(); break; case HttpStatusCode.Found: this.SetErrorCondition(HttpStatusCode.Redirect.ToString()); this.SetIsRedirect(); break; // 400 Range case HttpStatusCode.BadRequest: this.SetErrorCondition(HttpStatusCode.BadRequest.ToString()); this.SetIsNotRedirect(); break; case HttpStatusCode.Unauthorized: this.SetErrorCondition(HttpStatusCode.Unauthorized.ToString()); this.SetIsNotRedirect(); break; case HttpStatusCode.PaymentRequired: this.SetErrorCondition(HttpStatusCode.PaymentRequired.ToString()); this.SetIsNotRedirect(); break; case HttpStatusCode.Forbidden: this.SetErrorCondition(HttpStatusCode.Forbidden.ToString()); this.SetIsNotRedirect(); break; case HttpStatusCode.NotFound: this.SetErrorCondition(HttpStatusCode.NotFound.ToString()); this.SetIsNotRedirect(); break; case HttpStatusCode.MethodNotAllowed: this.SetErrorCondition(HttpStatusCode.MethodNotAllowed.ToString()); this.SetIsNotRedirect(); break; case HttpStatusCode.Gone: this.SetErrorCondition(HttpStatusCode.Gone.ToString()); this.SetIsNotRedirect(); break; case HttpStatusCode.RequestUriTooLong: this.SetErrorCondition(HttpStatusCode.RequestUriTooLong.ToString()); this.SetIsNotRedirect(); break; // Unhandled default: throw new MacroscopeDocumentException("Unhandled HttpStatusCode Type"); } } catch (MacroscopeDocumentException ex) { this.DebugMsg(string.Format("MacroscopeDocumentException: {0}", ex.Message)); } /** Raw HTTP Headers ------------------------------------------------- **/ this.SetHttpResponseStatusLine(Response: Response); this.SetHttpResponseHeaders(Response: Response); /** Server Information ----------------------------------------------- **/ /*{ * this.ServerName = ResponseHeaders.Server.First().ToString(); * }*/ /** PROBE HTTP HEADERS ----------------------------------------------- **/ /** Server HTTP Header ----------------------------------------------- **/ try { HttpHeaderValueCollection <ProductInfoHeaderValue> HeaderValue = ResponseHeaders.Server; if (HeaderValue != null) { if (HeaderValue.FirstOrDefault() != null) { this.SetServerName(HeaderValue.FirstOrDefault().ToString()); } } } catch (Exception ex) { this.DebugMsg(ex.Message); FindHttpResponseHeaderCallback Callback = delegate(IEnumerable <string> HeaderValues) { this.SetServerName(HeaderValues.First().ToString()); return(true); }; if (!this.FindHttpResponseHeader(ResponseHeaders: ResponseHeaders, HeaderName: "server", Callback: Callback)) { this.FindHttpContentHeader(ContentHeaders: ContentHeaders, HeaderName: "server", Callback: Callback); } } this.DebugMsg(string.Format("this.ServerName: {0}", this.ServerName)); /** Content-Type HTTP Header ----------------------------------------- **/ try { MediaTypeHeaderValue HeaderValue = ContentHeaders.ContentType; if (HeaderValue != null) { this.DebugMsg(string.Format("HeaderValue: {0}", HeaderValue)); this.MimeType = HeaderValue.MediaType; if (HeaderValue.CharSet != null) { this.SetCharacterSet(HeaderValue.CharSet); // TODO: Implement character set probing this.SetCharacterEncoding(NewEncoding: new UTF8Encoding()); } } } catch (Exception ex) { this.DebugMsg(string.Format("MediaType Exception: {0}", ex.Message)); this.MimeType = MacroscopeConstants.DefaultMimeType; } this.DebugMsg(string.Format("this.MimeType: {0}", this.MimeType)); /** Content-Length HTTP Header --------------------------------------- **/ try { long?HeaderValue = null; if (ContentHeaders.Contains("Content-Length")) { HeaderValue = ContentHeaders.ContentLength; } if (HeaderValue != null) { this.ContentLength = HeaderValue; } else { this.ContentLength = 0; } } catch (Exception ex) { this.DebugMsg(ex.Message); this.SetContentLength(Length: 0); FindHttpResponseHeaderCallback Callback = delegate(IEnumerable <string> HeaderValues) { this.SetContentLength(Length: long.Parse(HeaderValues.FirstOrDefault())); return(true); }; if (!this.FindHttpResponseHeader(ResponseHeaders: ResponseHeaders, HeaderName: "content-length", Callback: Callback)) { this.FindHttpContentHeader(ContentHeaders: ContentHeaders, HeaderName: "content-length", Callback: Callback); } } this.DebugMsg(string.Format("this.GetContentLength(): {0}", this.GetContentLength())); /** Content-Encoding HTTP Header ------------------------------------- **/ try { ICollection <string> HeaderValue = ContentHeaders.ContentEncoding; if (HeaderValue != null) { this.ContentEncoding = HeaderValue.FirstOrDefault(); } } catch (Exception ex) { this.DebugMsg(ex.Message); FindHttpResponseHeaderCallback Callback = delegate(IEnumerable <string> HeaderValues) { this.ContentEncoding = HeaderValues.FirstOrDefault(); return(true); }; if (!this.FindHttpResponseHeader(ResponseHeaders: ResponseHeaders, HeaderName: "content-encoding", Callback: Callback)) { this.FindHttpContentHeader(ContentHeaders: ContentHeaders, HeaderName: "content-encoding", Callback: Callback); } } if (string.IsNullOrEmpty(this.CompressionMethod) && (!string.IsNullOrEmpty(this.ContentEncoding))) { this.IsCompressed = true; this.CompressionMethod = this.ContentEncoding; } this.DebugMsg(string.Format("this.ContentEncoding: {0}", this.ContentEncoding)); this.DebugMsg(string.Format("this.CompressionMethod: {0}", this.CompressionMethod)); /** Date HTTP Header ------------------------------------------------- **/ try { DateTimeOffset?HeaderValue = ResponseHeaders.Date; if (HeaderValue != null) { this.DateServer = MacroscopeDateTools.ParseHttpDate(DateString: HeaderValue.ToString()); } } catch (Exception ex) { this.DebugMsg(ex.Message); this.DateServer = new DateTime(); FindHttpResponseHeaderCallback Callback = delegate(IEnumerable <string> HeaderValues) { this.DateServer = MacroscopeDateTools.ParseHttpDate(DateString: HeaderValues.First().ToString()); return(true); }; if (!this.FindHttpResponseHeader(ResponseHeaders: ResponseHeaders, HeaderName: "date", Callback: Callback)) { this.FindHttpContentHeader(ContentHeaders: ContentHeaders, HeaderName: "date", Callback: Callback); } } this.DebugMsg(string.Format("this.DateServer: {0}", this.DateServer)); /** Last-Modified HTTP Header ---------------------------------------- **/ try { DateTimeOffset?HeaderValue = ContentHeaders.LastModified; if (HeaderValue != null) { this.DateModified = MacroscopeDateTools.ParseHttpDate(DateString: HeaderValue.ToString()); } } catch (Exception ex) { this.DebugMsg(ex.Message); this.DateModified = new DateTime(); FindHttpResponseHeaderCallback Callback = delegate(IEnumerable <string> HeaderValues) { this.DateModified = MacroscopeDateTools.ParseHttpDate(DateString: HeaderValues.First().ToString()); return(true); }; if (!this.FindHttpResponseHeader(ResponseHeaders: ResponseHeaders, HeaderName: "last-modified", Callback: Callback)) { this.FindHttpContentHeader(ContentHeaders: ContentHeaders, HeaderName: "last-modified", Callback: Callback); } } this.DebugMsg(string.Format("this.DateModified: {0}", this.DateModified)); /** Expires HTTP Header ---------------------------------------------- **/ try { DateTimeOffset?HeaderValue = ContentHeaders.Expires; if (HeaderValue != null) { this.DateExpires = MacroscopeDateTools.ParseHttpDate(DateString: HeaderValue.ToString()); } } catch (Exception ex) { this.DebugMsg(ex.Message); this.DateExpires = new DateTime(); FindHttpResponseHeaderCallback Callback = delegate(IEnumerable <string> HeaderValues) { this.DateExpires = MacroscopeDateTools.ParseHttpDate(DateString: HeaderValues.First().ToString()); return(true); }; if (!this.FindHttpResponseHeader(ResponseHeaders: ResponseHeaders, HeaderName: "expires", Callback: Callback)) { this.FindHttpContentHeader(ContentHeaders: ContentHeaders, HeaderName: "expires", Callback: Callback); } } this.DebugMsg(string.Format("this.DateExpires: {0}", this.DateExpires)); /** HTST Policy HTTP Header ------------------------------------------ **/ // https://www.owasp.org/index.php/HTTP_Strict_Transport_Security_Cheat_Sheet // Strict-Transport-Security: max-age=31536000; includeSubDomains; preload { FindHttpResponseHeaderCallback Callback = delegate(IEnumerable <string> HeaderValues) { this.HypertextStrictTransportPolicy = true; return(true); }; if (!this.FindHttpResponseHeader(ResponseHeaders: ResponseHeaders, HeaderName: "strict-transport-security", Callback: Callback)) { this.FindHttpContentHeader(ContentHeaders: ContentHeaders, HeaderName: "strict-transport-security", Callback: Callback); } } this.DebugMsg(string.Format("this.HypertextStrictTransportPolicy: {0}", this.HypertextStrictTransportPolicy)); /** Location (Redirect) HTTP Header ---------------------------------- **/ try { Uri HeaderValue = ResponseHeaders.Location; if (HeaderValue != null) { this.SetUrlRedirectTo(Url: HeaderValue.ToString()); } } catch (Exception ex) { this.DebugMsg(ex.Message); FindHttpResponseHeaderCallback Callback = delegate(IEnumerable <string> HeaderValues) { this.SetUrlRedirectTo(Url: HeaderValues.FirstOrDefault().ToString()); return(true); }; if (!this.FindHttpResponseHeader(ResponseHeaders: ResponseHeaders, HeaderName: "location", Callback: Callback)) { this.FindHttpContentHeader(ContentHeaders: ContentHeaders, HeaderName: "location", Callback: Callback); } } this.DebugMsg(string.Format("this.GetIsRedirect(): {0}", this.GetIsRedirect())); this.DebugMsg(string.Format("this.GetUrlRedirectTo(): {0}", this.GetUrlRedirectTo())); /** Link HTTP Headers ------------------------------------------------ **/ { FindHttpResponseHeaderCallback Callback = delegate(IEnumerable <string> HeaderValues) { foreach (string HeaderValue in HeaderValues) { this.DebugMsg(string.Format("HeaderValue: {0}", HeaderValue)); this.ProcessHttpLinkHeader(HttpLinkHeader: HeaderValue); } return(true); }; if (!this.FindHttpResponseHeader(ResponseHeaders: ResponseHeaders, HeaderName: "link", Callback: Callback)) { this.FindHttpContentHeader(ContentHeaders: ContentHeaders, HeaderName: "link", Callback: Callback); } } /** ETag HTTP Header ------------------------------------------------- **/ try { EntityTagHeaderValue HeaderValue = ResponseHeaders.ETag; if (HeaderValue != null) { string ETagValue = HeaderValue.Tag; if (!string.IsNullOrEmpty(ETagValue)) { this.SetEtag(HeaderValue.Tag); } } } catch (Exception ex) { this.DebugMsg(ex.Message); FindHttpResponseHeaderCallback Callback = delegate(IEnumerable <string> HeaderValues) { string HeaderValue = HeaderValues.FirstOrDefault(); if (HeaderValue != null) { if (!string.IsNullOrEmpty(HeaderValue)) { this.SetEtag(HeaderValue); } } return(true); }; if (!this.FindHttpResponseHeader(ResponseHeaders: ResponseHeaders, HeaderName: "etag", Callback: Callback)) { this.FindHttpContentHeader(ContentHeaders: ContentHeaders, HeaderName: "etag", Callback: Callback); } } this.DebugMsg(string.Format("this.Etag: {0}", this.Etag)); /** WWW-AUTHENTICATE HTTP Header ------------------------------------- **/ // Reference: http://httpbin.org/basic-auth/user/passwd try { HttpHeaderValueCollection <AuthenticationHeaderValue> HeaderValue = ResponseHeaders.WwwAuthenticate; if (HeaderValue != null) { string Scheme = null; string Realm = null; foreach (AuthenticationHeaderValue AuthenticationValue in HeaderValue) { Scheme = AuthenticationValue.Scheme; string Parameter = AuthenticationValue.Parameter; Match Matched = Regex.Match(Parameter, "^[^\"]+\"([^\"]+)\""); if (Matched.Success) { Realm = Matched.Groups[1].Value; } } if (!string.IsNullOrEmpty(Scheme) && !string.IsNullOrEmpty(Realm)) { if (Scheme.ToLower() == "basic") { this.SetAuthenticationType(MacroscopeConstants.AuthenticationType.BASIC); this.SetAuthenticationRealm(Realm); } else { this.SetAuthenticationType(MacroscopeConstants.AuthenticationType.UNSUPPORTED); } } } } catch (Exception ex) { this.DebugMsg(ex.Message); } this.DebugMsg(string.Format("WwwAuthenticate: \"{0}\", Realm: \"{1}\"", this.GetAuthenticationType(), this.GetAuthenticationRealm())); /** Process Dates ---------------------------------------------------- **/ { if (this.DateServer.Date == new DateTime().Date) { this.DateServer = DateTime.UtcNow; } if (this.DateModified.Date == new DateTime().Date) { this.DateModified = this.DateServer; } } /** Process MIME Type ------------------------------------------------ **/ { Regex reIsHtml = new Regex(@"^(text/html|application/xhtml+xml)", RegexOptions.IgnoreCase); Regex reIsCss = new Regex(@"^text/css", RegexOptions.IgnoreCase); Regex reIsJavascript = new Regex(@"^(application/javascript|text/javascript)", RegexOptions.IgnoreCase); Regex reIsImage = new Regex(@"^image/(gif|png|jpeg|bmp|webp|vnd.microsoft.icon|x-icon)", RegexOptions.IgnoreCase); Regex reIsPdf = new Regex(@"^application/pdf", RegexOptions.IgnoreCase); Regex reIsAudio = new Regex(@"^audio/[a-z0-9]+", RegexOptions.IgnoreCase); Regex reIsVideo = new Regex(@"^video/[a-z0-9]+", RegexOptions.IgnoreCase); Regex reIsXml = new Regex(@"^(application|text)/(atom\+xml|xml)", RegexOptions.IgnoreCase); Regex reIsText = new Regex(@"^(text)/(plain)", RegexOptions.IgnoreCase); if (reIsHtml.IsMatch(this.MimeType)) { this.SetDocumentType(Type: MacroscopeConstants.DocumentType.HTML); } else if (reIsCss.IsMatch(this.MimeType)) { this.SetDocumentType(Type: MacroscopeConstants.DocumentType.CSS); } else if (reIsJavascript.IsMatch(this.MimeType)) { this.SetDocumentType(Type: MacroscopeConstants.DocumentType.JAVASCRIPT); } else if (reIsImage.IsMatch(this.MimeType)) { this.SetDocumentType(Type: MacroscopeConstants.DocumentType.IMAGE); } else if (reIsPdf.IsMatch(this.MimeType)) { this.SetDocumentType(Type: MacroscopeConstants.DocumentType.PDF); } else if (reIsAudio.IsMatch(this.MimeType)) { this.SetDocumentType(Type: MacroscopeConstants.DocumentType.AUDIO); } else if (reIsVideo.IsMatch(this.MimeType)) { this.SetDocumentType(Type: MacroscopeConstants.DocumentType.VIDEO); } else if (reIsXml.IsMatch(this.MimeType)) { this.SetDocumentType(Type: MacroscopeConstants.DocumentType.XML); } else if (reIsText.IsMatch(this.MimeType)) { this.SetDocumentType(Type: MacroscopeConstants.DocumentType.TEXT); } else { this.SetDocumentType(Type: MacroscopeConstants.DocumentType.BINARY); } } /** Process Cookies -------------------------------------------------- **/ // https://stackoverflow.com/questions/29224734/how-to-read-cookies-from-httpresponsemessage { try { CookieContainer CookieMonster = MacroscopeHttpTwoClient.GetCookieMonster(); CookieCollection Biscuits = CookieMonster.GetCookies(uri: this.GetUri()); this.AddCookies(Cookies: Biscuits); this.DebugMsg("cookies"); // CookieContainer CookieTin = MacroscopeHttpTwoClient.GetCookieMonster(); // string LimpBizkit = tin.GetCookieHeader( uri: Request.RequestUri ); } catch (Exception ex) { this.DebugMsg(ex.Message); } } return; }