FiftyOne.Foundation.Mobile.Detection.WebProvider.GetRequiredHeaders C# (CSharp) Метод

GetRequiredHeaders() приватный статический Метод

Gets the required headers. If the MVC method SetBrowserOverride has been used the User-Agent will be escapted and may contain + characters which need to be removed.
Requests after SetOverrideBrowser are still expected to use the overriden alias. The override useragent is stored in cookie which ASP.NET unpacks automatically, however it is url encoded with pluses instead of spaces. This code transforms the useragent back, but a new NameValueCollection is needed as the original collection cannot be modified.
private static GetRequiredHeaders ( HttpRequest request ) : NameValueCollection
request System.Web.HttpRequest
Результат System.Collections.Specialized.NameValueCollection
        private static NameValueCollection GetRequiredHeaders(HttpRequest request)
        {
            // A useragent might be url encoded if SetOverrideBrowser was used in a previous request.
            // This is checked by comparing the escaped string is different against the original.

            NameValueCollection headers;
            var escapedUA = request.UserAgent != null ?
                Uri.UnescapeDataString(request.UserAgent).Replace('+', ' ') :
                null;
            if (escapedUA != request.UserAgent)
            {
                // Requests after SetOverrideBrowser are still expected to use the overriden alias.
                // The override useragent is stored in cookie which ASP.NET unpacks automatically, however
                // it is url encoded with pluses instead of spaces. This code transforms the useragent back,
                // but a new NameValueCollection is needed as the original collection cannot be modified.
                headers = new NameValueCollection(request.Headers.Count, request.Headers);
                foreach (var componentHeader in ActiveProvider.DataSet.Components.SelectMany(i => i.HttpHeaders).Distinct())
                {
                    if (headers[componentHeader] != null)
                    {
                        headers[componentHeader] = escapedUA;
                        break;
                    }
                }
            }
            else
            {
                // No MVC defect so use the headers unaltered.
                headers = request.Headers;
            }
            return headers;
        }