diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b47bb23 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +# editorconfig.org +root = true + +[*] +indent_style = space +end_of_line = crlf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[**/*.{config,csproj,dotsettings,feature,fxcop,js,json,markdown,md,ncrunch*,ndepend,rb,targets,xml,xsd}] +indent_size = 2 + +[**/*.cs] +indent_size = 4 \ No newline at end of file diff --git a/Prerender.io/PrerenderConfigSection.cs b/Prerender.io/PrerenderConfigSection.cs index f618cec..50ff406 100644 --- a/Prerender.io/PrerenderConfigSection.cs +++ b/Prerender.io/PrerenderConfigSection.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Configuration; @@ -20,18 +20,18 @@ public String PrerenderServiceUrl } } - [ConfigurationProperty("stripApplicationNameFromRequestUrl", DefaultValue = false)] - public bool StripApplicationNameFromRequestUrl - { - get - { - return (bool)this["stripApplicationNameFromRequestUrl"]; - } - set - { - this["stripApplicationNameFromRequestUrl"] = value; - } - } + [ConfigurationProperty("stripApplicationNameFromRequestUrl", DefaultValue = false)] + public bool StripApplicationNameFromRequestUrl + { + get + { + return (bool)this["stripApplicationNameFromRequestUrl"]; + } + set + { + this["stripApplicationNameFromRequestUrl"] = value; + } + } [ConfigurationProperty("whitelist")] public String WhitelistString diff --git a/Prerender.io/PrerenderModule.cs b/Prerender.io/PrerenderModule.cs index b9329ae..3cf8c7b 100644 --- a/Prerender.io/PrerenderModule.cs +++ b/Prerender.io/PrerenderModule.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Configuration; using System.Diagnostics; @@ -139,15 +139,15 @@ private String GetApiUrl(HttpRequest request) } // Remove the application from the URL - if (_prerenderConfig.StripApplicationNameFromRequestUrl && !string.IsNullOrEmpty(request.ApplicationPath) && request.ApplicationPath != "/") - { - // http://test.com/MyApp/?_escape_=/somewhere - url = url.Replace(request.ApplicationPath, string.Empty); - } - + if (_prerenderConfig.StripApplicationNameFromRequestUrl && !string.IsNullOrEmpty(request.ApplicationPath) && request.ApplicationPath != "/") + { + // http://test.com/MyApp/?_escape_=/somewhere + url = url.Replace(request.ApplicationPath, string.Empty); + } + var prerenderServiceUrl = _prerenderConfig.PrerenderServiceUrl; return prerenderServiceUrl.EndsWith("/") - ? (prerenderServiceUrl + url) + ? prerenderServiceUrl + url : string.Format("{0}/{1}", prerenderServiceUrl, url); } @@ -162,7 +162,7 @@ public static string RemoveQueryStringByKey(string url, string key) newQueryString.Remove(key); // this gets the page path from root without QueryString - string pagePathWithoutQueryString = uri.GetLeftPart(UriPartial.Path); + var pagePathWithoutQueryString = uri.GetLeftPart(UriPartial.Path); return newQueryString.Count > 0 ? String.Format("{0}?{1}", pagePathWithoutQueryString, newQueryString) @@ -178,10 +178,6 @@ private bool ShouldShowPrerenderedPage(HttpRequest request) var blacklist = _prerenderConfig.Blacklist; if (blacklist != null && IsInBlackList(url, referer, blacklist)) - - - - { return false; } @@ -205,15 +201,16 @@ private bool ShouldShowPrerenderedPage(HttpRequest request) { return false; } + if (IsInResources(url)) { return false; } - return true; + return true; } - private bool IsInBlackList(Uri url, string referer, IEnumerable blacklist) + private static bool IsInBlackList(Uri url, string referer, IEnumerable blacklist) { return blacklist.Any(item => { @@ -222,7 +219,7 @@ private bool IsInBlackList(Uri url, string referer, IEnumerable blacklis }); } - private bool IsInWhiteList(Uri url, IEnumerable whiteList) + private static bool IsInWhiteList(Uri url, IEnumerable whiteList) { return whiteList.Any(item => new Regex(item).IsMatch(url.AbsoluteUri)); } @@ -238,7 +235,7 @@ private IEnumerable GetExtensionsToIgnore() var extensionsToIgnore = new List(new[]{".js", ".css", ".less", ".png", ".jpg", ".jpeg", ".gif", ".pdf", ".doc", ".txt", ".zip", ".mp3", ".rar", ".exe", ".wmv", ".doc", ".avi", ".ppt", ".mpg", ".mpeg", ".tif", ".wav", ".mov", ".psd", ".ai", ".xls", ".mp4", ".m4a", ".swf", ".dat", ".dmg", - ".iso", ".flv", ".m4v", ".torrent"}); + ".iso", ".flv", ".m4v", ".torrent", ".xml"}); if (_prerenderConfig.ExtensionsToIgnore.IsNotEmpty()) { extensionsToIgnore.AddRange(_prerenderConfig.ExtensionsToIgnore); @@ -276,7 +273,7 @@ private IEnumerable GetCrawlerUserAgents() return crawlerUserAgents; } - private bool HasEscapedFragment(HttpRequest request) + private static bool HasEscapedFragment(HttpRequest request) { return request.QueryString.AllKeys.Contains(_Escaped_Fragment); }