You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This initially manifested itself by getting 2 calls to the IHttpModule from a single perceived request.
How to reproduce.
My Rule
where I have a custom encoder, which rewrites the url to
/CDNInternal/CC?remaining=abc
1. My Custom Transform
public class CDNUrlEncodeTransform : IRewriteTransform
{
public string ApplyTransform(string input)
{
const string strRegex = @"(?^.+?(?=\/))\/(?.*)";
var myRegex = new Regex(strRegex, RegexOptions.None);
var strTargetString = input;
var matches = myRegex.Matches(strTargetString);
foreach (Match myMatch in matches)
{
if (myMatch.Success)
{
var key = myMatch.Groups["key"].Value;
var remaining = myMatch.Groups["remaining"].Value;
var encodedRemaining = HttpUtility.UrlEncode(remaining);
var finalUrl = string.Format("/CDNInternal/{0}?remaining={1}", key, encodedRemaining);
return finalUrl;
}
}
return input;
}
public string Name
{
get
{
return "CDNUrlEncode";
}
}
}
2. What happens.
The first request comes in:
If you check the Request you will see the following in the second request.
RequestUrl = /CDN/CC/Plugins/a.1.2.3.4/a.jpg
RawUrl = /CDN/CC/Plugins/a.1.2.3.4/a.jpg
Custom Transform transforms it to the following:
From: /CDN/CC/Plugins/a.1.2.3.4/a.jpg
To: /CDNInternal/CC?remaining=[encoded Plugins/a.1.2.3.4/a.jpg]
This results in a second request coming in reflecting the new rewrite. If you check the Request you will see the following in the second request. The RequestUrl and the RawUrl are the same. Might be a asp.net MVC 5.2 issue.
This causes a rewrite to happen again because it matches the original rule. I would think this should cause an infinite look, but it stopped at 2. Did not investigate that further.
This initially manifested itself by getting 2 calls to the IHttpModule from a single perceived request.
How to reproduce.
}
2. What happens.
The first request comes in:
If you check the Request you will see the following in the second request.
RequestUrl = /CDN/CC/Plugins/a.1.2.3.4/a.jpg
RawUrl = /CDN/CC/Plugins/a.1.2.3.4/a.jpg
Custom Transform transforms it to the following:
From: /CDN/CC/Plugins/a.1.2.3.4/a.jpg
To: /CDNInternal/CC?remaining=[encoded Plugins/a.1.2.3.4/a.jpg]
This results in a second request coming in reflecting the new rewrite. If you check the Request you will see the following in the second request. The RequestUrl and the RawUrl are the same. Might be a asp.net MVC 5.2 issue.
RequestUrl = /CDNInternal/CC?remaining=[encoded Plugins/a.1.2.3.4/a.jpg]
RawUrl = /CDN/CC/Plugins/a.1.2.3.4/a.jpg
This causes a rewrite to happen again because it matches the original rule. I would think this should cause an infinite look, but it stopped at 2. Did not investigate that further.
Here is the fix:
https://github.com/sethyates/urlrewriter/blob/master/src/RewriterEngine.cs
public class RewriterEngine
{
public void Rewrite()
{
string originalUrl = _httpContext.RequestUrl.PathAndQuery.Replace("+", " ");
...}
}
replace
string originalUrl = _httpContext.RawUrl.Replace("+", " ");
with
string originalUrl = _httpContext.RequestUrl.PathAndQuery.Replace("+", " ");
The text was updated successfully, but these errors were encountered: